Creating and Opening Files with Nano
In this step, you will learn how to create a new text file and open it with the nano editor. The nano editor provides a simple interface for text editing in the terminal.
First, navigate to your project directory:
cd ~/project
You should now be in the /home/labex/project
directory. Let's create a new file named notes.txt
using the touch
command:
touch notes.txt
The touch
command creates an empty file if it doesn't exist. Now, let's open this file with the nano editor:
nano notes.txt
After running this command, you should see the nano editor interface in your terminal. It looks like this:
GNU nano 6.2 notes.txt
^G Help ^O Write Out ^W Where Is ^K Cut ^J Justify
^X Exit ^R Read File ^\ Replace ^U Paste ^T To Spell
The nano interface displays the filename at the top and a list of available commands at the bottom. The ^
symbol represents the Ctrl
key. For example, ^X
means pressing Ctrl + X
to exit the editor.
Type the following text in the editor:
This is my first file using nano editor.
Linux text editing is straightforward!
Now, let's save the file and exit the editor:
- Press
Ctrl + X
to exit
- You will be asked if you want to save the modified buffer. Press
Y
to confirm.
- Press
Enter
to confirm the filename and save the file.
You have successfully created and edited a file using nano. Let's verify the content of the file using the cat
command:
cat notes.txt
This should display the text you just entered.