Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands for linux to edit files

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail what the linux editing commands are, and the editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

The command to edit a file in linux is: 1, the nano command, which is used to open the specified file for editing, the syntax is "nano [option] [[+ row, column] file name]"; 2, the vi command, vi is also used to edit the file, the syntax is "vi file name".

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Linux commands for Editing Files

Linux comes with two text editors: vi and nano.

Use nano to edit the file:

Nano file name

Click Ctrl-X to exit editing and choose whether to save changes to the file.

The nano command can open a specified file for editing. By default, it automatically breaks lines, that is, it automatically splits into several lines when you enter too long content in a line, but it may cause problems in dealing with some files in this way.

For example, in the configuration file of the Linux system, automatic line breaking will break the content that can only be written on one line into multiple lines, which may cause the system to fail. So, if you want to avoid this, add the-w option.

Use vi to edit the file:

Vi file name

Vi has two modes: one is edit mode and the other is command mode. Click I to enter edit mode from command mode, and click the ESC key to re-enter command mode. We generally enter the editing mode to add, modify, and delete.

But when we delete and modify too much content, we use the command line mode to modify, which is convenient and fast, and in the command line, the most commonly used are the four commands: X: delete the current character; dd: delete the current line; u: restore the previous step; p: copy the previously deleted line.

Basically, vi can be divided into three states: command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

1) Command line mode command mode)

Control the movement of the screen cursor, the deletion of characters, words or lines, move and copy a section and enter the Insert mode, or to the last line mode.

2) insert mode (Insert mode)

Text input can only be done under Insert mode, and press the "ESC" key to return to command line mode.

3) bottom line mode (last line mode)

To save or exit vi, you can also set the editing environment, such as finding strings, listing line numbers, etc. Wait.

However, when we use vi, we usually simplify it into two modes, that is, the last line mode mode is also included in the command line mode command mode).

This is the end of this article on "what are the commands for editing linux files?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report