Linux File Editing: A Guide to Vim and Nano Commands

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:

  1. The Root Directory ("/") - It contains essential system files and directories, and all other directories stem from it.
  2. /bin and /sbin - /bin stores essential command binaries required for the system's single-user mode and for users to execute common commands. While /sbin holds binary executables used by system administrators for system maintenance.
  3. /home - contains home directories for each user.
  4. /etc - contains system configuration files and directories.
  5. /var - contains data that changes frequently while the system is running.
  6. /tmp - used to store the data used by the system and user applications for a short period of time.
  7. /dev - contains the special device files for all the devices attached to the system.
  8. /usr - stores user related programs, libraries, docs and other files.
  9. /boot - contains the files required for the system's boot process, including the Linux kernel and bootloader configurations.
  10. /opt - reserved for the installation of add-on application software packages.

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:

  • To open a file with Nano, type the following command in your terminal:

nano filename        

  • Basic navigationThe arrow keys are used to navigate on the page that is to move the curso up, down, right or left.
  • Editing textBy default it opens in command mode, to enter text just start typong. In additon to inserting text into the file other commands are usually listed at the bottom of the file but some major combiantion include:CTRL+X - Quit nanoCTRL+O - Save the fileCTRL+K - Cut textCTRL+U - Paste textCTRL+G - Get help

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 ??

Intro to Linux Fundamentals - What is Linux?

Linux Command Line - Linux Fundamentals

Linux Users and Groups



要查看或添加评论,请登录

Hillary Nyakundi的更多文章

  • Linux Users and Groups

    Linux Users and Groups

    One of the core skills required while working as a system administrator or any related role is understanding the…

  • Linux Command Line - Linux Fundamentals

    Linux Command Line - Linux Fundamentals

    The Linux Command Line plays a really important role in enabling users to interact with cloud resources. Understanding…

  • Intro to Linux Fundamentals - What is Linux?

    Intro to Linux Fundamentals - What is Linux?

    The Linux kernel has found its way into many diverse systems. It can now be found in everything from automobiles to…

    3 条评论
  • What is Cloud Computing?

    What is Cloud Computing?

    Cloud computing has become an important part of today’s technology space, where every organization is slowly shifting…

  • Cloud Computing Basics - Beginner's Guide to Servers, Data Centers, and Software Development

    Cloud Computing Basics - Beginner's Guide to Servers, Data Centers, and Software Development

    In today's exploration of basic computing concepts, we look at the elements that power most resources relied on by many…

    2 条评论
  • Introduction to Computing - Cloud Foundations

    Introduction to Computing - Cloud Foundations

    Cloud has turned out to be an important part of changing how we interact with computers. As part of the Amazon Web…

    1 条评论
  • AWS re/Start - Cloud Computing for Beginners

    AWS re/Start - Cloud Computing for Beginners

    As technology continues to evolve, the need to acquire new skills is irresistible, especially when it comes to…

    2 条评论

社区洞察

其他会员也浏览了