Linux File Editing: A Guide to Vim and Nano Commands
In Linux systems one of the core skills for system adminstartaion is being able to work with files, this involves, creating, updating, reading and deleting them. File editing extends beyond the normal manipulation
Read along to get an understanding of the eseential aspects of editing files in Linux, including the most commonly used text editors like Nano and Vim. This article caters for expertice of all levels whether a newbie or have been in the field for some time but facing issues with this text editors this guide is for you.
Understanding the Linux File System
The Linux file system is structured in a hierarchical manner, resembling a tree, with the root directory ("/") at the top. Below is an overview of the file system:
Basic Text Editors
Linux supportsa variety of text edotors each with it's strngths and learning curves. In this section we are going to have a look at the most common used editors in Linux systems, that is Nano nad Vim.
Vim
It's the default text editor for most Linux distributions and understanding it is essential. Vim has no menu buttons as it's a command line tool. It uses three different modes, that is command mode, insert mode and visual mode.
To open a file with vim, use the following command:
vim filename
Command mode
The command mode has support for diferent keys which support different fucntionalities. To switch to command mode press ESC on the keyboard.
The most common ones are shown below:
Other important vim commands are:
The Insert mode
This mode allows you to enter text into the body of the file. To switch to the insert mode press i on the keyboard followed by the text you want to input in the file. To exit this mode press ECS key.
To be sure you are in the insert mode you should be able to see it reflect at the bottom of the terminal as shown below:
Quitting and saving
领英推荐
To save what you have entered in your file, from the command mode press :w to save your changes and to exit pres :q. Alternatively you can just type :wq to save and exit. Other helpful commands include:
Be sure that you are comfortable with these commands, as you will need them while working with Vim.
In a case you are stack, you can activate the Vimtutor by running the Vimtutor command. It opens up the tutorial with common vim tasks.
Nano
This is another lightweight text editor that works direclty from the shell. It's astill a common choice though it's not usually installed on every distribution. Some of the common commands include:
nano filename
Checkpoint Questions
To test your knowledge up to this point, I invite you to reflect on this checkpoint questions and gauge your understanding of vima and nano.
Conclusion
In conclusion, mastering this two text editors is essental as most Linux configuartions are held in text files and you must be able to modify them in order to modify the system configurations.
Remember to practice as thisis the key to mastery. Be sure to enage with the command covered here and utilize the vimtutor as its an helpul tool.
That marks it for this lesson, stay tuned for the next article from my AWS re/Start program journey. In addition to this check out my other pieces from this learning series below ??