How To Create A File With Nano On Linux For Beginners
Quick, copy-friendly instructions and examples for creating and saving files using the nano text editor.
1. Open Nano And Create A New File
Run nano followed by the filename. If the file doesn't exist, nano will create it when you save.
nano filename.txt- If the file doesn't exist, nano will create it automatically when you save.
- If the file already exists, nano will open it for editing.
Example :
nano my-notes.txt2. Start typing
Once nano opens, simply type your content. Navigation keys (arrow keys, Home, End, PageUp, PageDown) work normally.
3. Save The file
Press the write-out shortcut :
CTRL + OThen press Enter to confirm the filename shown at the bottom.
4. Exit Nano
To close nano after saving (or if you want to exit) :
CTRL + XIf you try to exit without saving, nano will ask whether you want to save changes-press Y (yes) or N (no).
5. Verify the file exists
Back in your shell, list files to confirm :
ls -l filename.txtExample :
$ ls -l my-notes.txt
-rw-r--r-- 1 user user 123 Apr 15 12:34 my-notes.txtCommon examples
- Create a shell script file : nano script.sh (then save and make it executable with chmod +x script.sh).
- Create a config file in a directory (may need sudo) : sudo nano /etc/myconf.conf.
- Create a simple HTML file : nano index.html and paste your HTML.
Keyboard Shortcuts Cheat-Sheet
- CTRL + O - Save (Write Out)
- CTRL + X - Exit
- CTRL + K - Cut current line
- CTRL + U - Paste
- CTRL + W - Search (Where Is)
- CTRL + G - Help (shows full list)







