1. Use of vim editor
(1) Working mode of ViM editor:
(2) The use of vi editor
2. View the file contents
(1) more/less View all contents of the file
When the file content is too much, you can run the more or less command to view it.
Command format:
More filename
Less filename
(2) Cat view the file content
This command is used to print the content of a file to a monitor or terminal window.
Syntax: cat [option] File name
(3) head/tail Displays information about the head and tail of a file
The head command is used to view the first several lines of a file, and the tail command is used to view the last several lines of a file. By default, 10 lines are displayed.
Command format:
Head [option] File name
Tail [option] File name
(4) grep Query string
The grep command can match a string in a specified text file and output all the contents in the line where the string matches.
The command format is grep keyword search scope
3. Pipe symbol
Command format: * * * * cmd1 | cmd2 | cmd3 |… |cmd(n)
** Effect: ** executes the result of one command as another command input
Check the contents of the /etc directory.
#ls /etc | less
Display files whose names start with pass in the /etc directory
#ls /etc | grep pass*
4. Redirect
The so-called redirection refers to the redirection of the command to obtain or output information from non-default INPUT/output devices, rather than using the system standard INPUT/output, error port. Therefore, redirection is divided into input redirection, output redirection and error redirection.
Record the execution result of the ls/command in the list file.
#ls / > list
If the useradd lolo command fails to be executed, the error information is saved to the errlog file in the current directory.
#useradd lolo 2>errlog
[Example 3] Redirect the result and error message of hello program to outfile in/TMP.
#./hello &> /tmp/outfile
If you need more course resources, you can visit our website, which has many free online courses in all directions.