In the Nano file editor, it may not be obvious to a new user how to save and exit.
Most commands in Nano use the CTRL key plus another key. If you wanted to close a file without saving your changes, you would hold down the CTRL key and press the ‘x’ key briefly (for eXit). If anything has changed while you have the file open, it will prompt you to ask if you want to save your changes. At that point you would type the ‘n’ key if you don’t want to save anything, or the ‘y’ key if you do. If you choose to save, it will then prompt you for a file name. usually you will just hit the Enter key because it will default to the name of the file that you have open.
There is a little menu at the bottom of Nano that displays some of the more common commands. in that menu, the “caret” (^) represents the CTRL key.
I never can remember the key combination for saving my work, so my solution is to exit, and then save when prompted.
These commmands will do this:
^x
y
<enter>
Again, don’t type ‘enter’ just press the enter/return key on your keyboard.
If you think you messed up and want to enter without saving (there’s not really a useful undo command), you can just do
^x
n
This will kick you back out to the command line without saving your work & you can start over by reopening the file.
If you want to be really safe before you start editing important files, you can make a duplicate as a backup before you start editing. The linux “cp” (copy) command can easily do this. you just need to give it the name of a file you want to copy and the name you want to call the copy. to use the example from above,
sudo cp /boot/piaware-config.txt /boot/piaware-config-txt.bak
sudo = run the following command as root (super user)
cp = copy
/boot/piaware-config.txt = the name of the file we want to copy
/boot/piaware-config.txt.bak = the name of the backup file (we just added .bak to the file name).
Now, if you did a directory listing of the /boot/ folder, you would have both piaware-config.txt and piaware-config.txt.bak.
That backup copy will happily sit there and be completely ignored by the system. But if you manage to completely bork your ‘live’ config file, you can just delete it and rename the back up file.
sudo rm /boot/piaware-config.txt
sudo mv /boot/piaware-config.txt.bak /bootpiaware-config.txt
sudo reboot
The “delete” command in linux is rm (for remove). Linux doesn’t have an actual rename function, so it gets around that by using a “move” (mv) command - you just “move” a filename to a different filename to effect a rename.
Hope that adds some additional clarity.