This is a simple tutorial about "nano", my favourite linux text editor in the command line. Let's begin.
CREATING A NEW FILE
From the command line, type "nano" without quotes and press enter. Note that if you provide nano with a file name, it wont create a new file, only open the one you passed by, for example "nano /home/user/Documents/mytextFile.txt".
Once opened, you will see something like this.
Next, you move the cursor wherever you want to start typing.
Type anything, when you are done writing, simple press "Ctrl + O" (the plus sign you don't have to type it).
A message appears at the bottom of the window, it ask you to name the file, in the case it is a new file.
A message appears at the bottom of the window, it ask you to name the file, in the case it is a new file.
nano text editor file opened |
Now, type the name of the new file you want to create.
saving |
After you typed the name of the file, just press "ENTER" and it will be saved.
write confirmation |
The message says "Wrote 6 lines". well, that means it saved the file correctly.
Opening an existing file (read)
From the command line type:
$ nano myNewTextFile.txt
opened file |
You now see the text that the file had in it. Also check that it says at the bottom "Read 6 lines".
Now, you can start editing and when you are done, you can save it.
Now, you can start editing and when you are done, you can save it.
Press CTRL + O again, but this time, as we are opened an existing file it already shows us the name of the file at the bottom of the screen for overwriting it, or if we change the name it will create a new file with the new name you just typed.
saving file |
Press Enter to save and overwrite the existing file or "Ctrl + C" to cancel the operation.
To quit nano, press "Ctrl + X".
Notes:
CUT
To cut text, you will have to type "Ctrl + K", note that the whole line will be cut.
Notes:
CUT
To cut text, you will have to type "Ctrl + K", note that the whole line will be cut.
PASTE
To paste the line, type "Ctrl + U". You can paste what you cut the number of times you want.
READ/INJECT
When you type "Ctrl + R" it injects the file content you specify where the cursor is located.
SEARCH (Where is?)
Type "Ctrl + W" to search for a specific word, phrase, note that it is case insensitive, so UPPERCASE and lowercase characters are treated equally.
REPLACE
REPLACE
Type "Ctrl + \" to replace the word you want with the new text typed. You will have to confirm typing "Y" when asked, Also check that if you type A it will replace all the occurrences in the file. It is a three steps method, search, text to replace with, and confirmation.
This is all for now.
This is all for now.
See you in the next post.