Home  >  Article  >  Operation and Maintenance  >  What is the command to edit files in linux

What is the command to edit files in linux

WBOY
WBOYOriginal
2022-03-18 11:22:3825102browse

The commands to edit files in Linux are: 1. nano command, which is used to open the specified file for editing. The syntax is "nano [option] [[row, column] file name]"; 2. vi Command, vi is also used to edit files, the syntax is "vi file name".

What is the command to edit files in linux

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

What is the command to edit files in Linux

Linux comes with two text editors: vi and nano.

Use nano to edit files:

nano 文件名

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

The nano command can open the specified file for editing. By default, it will automatically break lines, that is, automatically split into several lines when too long content is entered in one line. However, some files are processed in this way. It may cause problems.

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 malfunction. Therefore, if you want to avoid this situation, add the -w option.

Use vi to edit files:

vi 文件名

vi has two modes: one is the editing mode and the other is the command mode. Click i to enter editing mode from command mode, and click esc to re-enter command mode. We usually enter edit mode to add, modify, and delete.

But when we delete and modify too much content, we use the command line mode to make modifications, which is convenient and fast. In the command line, the most commonly used ones are x, dd, u, p These 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, namely command mode, insert mode and last line mode. The functions of each mode are distinguished as follows:

1) Command line mode command mode)

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

2) Insert mode

Only in Insert mode, text input can be done. Press the "ESC" key to return to the command line mode.

3) Last line mode

Save the file or exit vi, you can also set the editing environment, such as searching for strings, listing line numbers, etc.

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

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the command to edit files in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn