Join Scott Simpson for an in-depth discussion in this video Creating and opening files from the command line, part of Learning nano.
- To create or edit a file from the Command line, type nano, followed by the path and file name you want to create or edit. Let's open up the example, php.ini file in the Exercise Files folder. I'll write the path to that using tab completion and then I'll press Enter. Up at the top of the screen, it shows the file name and says how many lines of the file were read down at the status bar. It's important to check the status line when you open files, just in case you happen to open a file read-only.
Let's see what that looks like. I'll press Ctrl + X to exit and instead of opening php.ini from the Exercise Files, I'll open the real one. I'll write nano /etc/php5/ apache2/php.ini and here, in the status line, I can see I don't have write permission to this file. So, if I make any changes here, they won't be reflected in the original file. I'll exit nano again and this time, I'll use sudo to gain permission to modify the file.
I'll use a little shortcut that I like, two exclamation marks, that tells sudo to rerun the last command, but this time, with sudo. And now, I don't have the warning about not being able to write to the file. I'll exit again and this time, I'll type nano my-file. This will create a new blank file with whatever name I specify. But, I don't need to do anything with that right now, so I'll exit. And that's about it for creating and opening files. Especially if you're working with configuration files, always make sure to check you have write permission before making your changes.
- Installing nano
- Editing and searching for text
- Saving files
- Using Undo and Spell Check
- Customizing nano