dev-resources.site
for different kinds of informations.
Guide to using โedโ editor in Linux
โedโ is a simple, straight-forward text editor available by default in Linux. It can be used to create / edit text files easily. If you ever get stuck in a situation where you donโt have access to advanced editors like โviโ (e.g., when trying to recover your system after a crash), or simply for fun, your knowledge of โedโ can help you.
Letโs go through a few basic commands for โedโ.
1. Invoking โedโ:
From the command line, invoke โedโ by using the command โedโ with (or without specifying) a file name. If a file name is specified, โedโ loads the file contents in buffer, and outputs the number of characters in the file. If no filename is specified, no output is displayed. You can infer that โedโ has been launched by noticing that the shell prompt (โ$โor โ#โ) is no longer available. Instead, you are welcomed by a blank line.
Here, I am invoking โedโ with a blank file (pramod.txt) that I created using โtouchโ command.
The editor responds with โ0โ since it is a blank file. Notice that the cursor on following line is not showing any โ$โ or โ#โ prompt.
2. Appending text:
Now, letโs add 2 lines of text to our empty file.In order to do so, use the โaโ command (for append). Once you type โaโ followed by ENTER, โedโ will wait for your inputs silently. It continues to store the inputs received in the buffer memory till the time you signal it to stop doing so by entering a โ.โ by itself on a blank line. Here is an example:
3. Reviewing file content:
In order to review the contents of a file, use the command โ,pโ. This will list out the entire contents of the file loaded in buffer, and allow you to review the same.
If you want to review specific lines in the file instead, simply type the corresponding line number (First line is line # 1).
4. Deleting a particular line:
If you want to delete any specific line, type in the line number followed by โdโ. E.g., in the screenshot shown below, I have deleted the first line, and am then listing the file contents using the โ,pโ command:
Notice that on reviewing the file contents after deleting the first line, I am only shown the 2nd line (which is what remains in the buffer memory).
5. Saving changes:
After having worked on the desired updates, donโt forget to save the changes to the disk by using the โwโ command. If you exit the editor without saving your changes, the same will be lost. Once you issue the โwโcommand, โedโ will respond with the updated character count for the file.
6. Exiting the editor:
Once you are satisfied with the updates to file content and want to return to the shell command prompt, use the โqโ command. Once you issue this command, you will be returned to the shell, and you can view the updated file contents using โcatโ command.
Thatโs it for now. Do remember to use โwโ command to save your changes before exiting the editor otherwise your changes wonโt be saved, and the file on disk will remain unaltered.
Thanks!
Featured ones: