Home > Article > Operation and Maintenance > What is the difference between vi and cat in linux
The difference between vi and cat: 1. Cat is a text printing command, while vi is a text editor; 2. The cat command is used to output file content information to the console, but it cannot edit files. The vi command can output file contents and edit (delete, search, replace) files.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
cat command introduction
The original meaning of the cat command is concatenation (concatenate), which is used to connect the contents of multiple files and output them to the standard output. stream (the standard output stream defaults to the screen). In actual application, we often use it to display file contents. If you are familiar with the type command under MS-DOS, I believe it is not difficult to master the cat command. Common examples of this command are as follows:
cat file1.txt
Display the contents of the file1.txt file;
cat file1.txt file2.txt
Display the contents of file1.txt and file2.txt files;
cat -n file1.txt
Display the contents of file1.txt file and display the line number;
vi command introduction
vi is the abbreviation of "Visual Interface". Its status on Linux is like the Edit program on DOS. It can perform many text operations such as output, delete, find, replace, block operations, etc., and users can customize it according to their own needs, which is not available in other editing programs.
vi is not a typesetting program. It is not like Word or WPS that can arrange fonts, formats, paragraphs and other attributes. It is just a text editing program.
vi has no menu, only commands, and there are many commands. Due to space limitations, this article only introduces commonly used commands.
Vi has three basic working modes: command line mode, text input mode and last line mode.
Command line mode:
At any time, no matter what mode the user is in, just press the "ESC" key to enter vi into the command line mode; when When you enter the vi command in the shell environment to start the vi editor, you are also in this mode.
In this mode, users can enter various legal vi commands to manage their own documents. At this time, any characters entered from the keyboard are interpreted as editing commands. If the entered characters are legal vi commands, vi will complete the corresponding actions after accepting the user commands (but it should be noted that the entered commands is not displayed on the screen). If the characters entered are not legal commands for vi, vi will sound an alarm.
Text input mode:
In command mode, enter the insert command i, append command a, open command o, modify command c, replace command r or replace command s can enter text input mode. In this mode, any characters entered by the user are saved by vi as file content and displayed on the screen. During the text input process, if you want to return to the command mode, just press the "ESC" key.
Last line mode:
In command mode, the user can enter the last line mode by pressing the ":" key. At this time, Vi will display the last line of the window. (usually the last line of the screen) displays a ":" as the last line mode prompt, waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the editing buffer to a file, etc.) After the last line of commands is executed, vi automatically returns to the command mode.
If you change your mind while entering a command in the last line mode, you can press the "ESC" key or use the backspace key to delete all the entered commands, and then press the backspace key again to make vi Return to command mode.
The difference between cat and vi/vim
The cat command is a text printing command under the Linux system. Use For outputting a text message to the console, the input of this command is similar to using word to open a document, but the document cannot be edited.
The vi/vim command is a command used to view and edit text under the Linux system. It can not only view but also edit.
Extension: The difference between vi and vim
vi does not need to be installed, open the code, the color is the same (black)
vim requires additional installation, open the code , use color to distinguish codes
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What is the difference between vi and cat in linux. For more information, please follow other related articles on the PHP Chinese website!