Linux provides a large number of commands, such as file management operations, disk operations, network management operations, process management, file attributes and permission settings.
1. Linux Command Line Composition
Command line format
Linux Command composition: shell internal commands + shell External commands. Shell Internal commands: the simplest and most commonly used commands. Memory is entered at shell startup. Shell External commands: Independent executable programs are some utility programs.
Command line format: command name [Option] [parameter 1] [parameter 2] ......
Example: find/-name "mysql"
Note: After the command is executed normally, a value of 0 is returned, indicating that the execution is successful. If an error occurs during the command execution and all the work is not completed, a non-0 value is returned, the meaning of the returned value varies with the command. In shell scripts, the return value of a command can be used as part of the control logic. After the command is executed, run the command echo $? To view the return value.
Linux Command Structure
1. Redirect
In Linux Command Line mode, if the input required by the command is not from the keyboard, but from the specified file, this is the input redirection. Similarly, the command output can be written to a specified file instead of displayed on the screen. This is the output redirection.
The general format of redirection:
Command [] <filename (standard input redirection)
Command []> filename (standard output redirection)
2. Pipeline
The pipeline "|" provided by LInux is used to separate the two commands. The output of the command on the left of the pipeline operator is used as the input of the command on the right of the pipeline operator. The continuous use of pipelines means that the output of the first command will be used as the input of the second command, and the output of the second command will be used as the input of the Third Command, and so on.
The common format of MPs queue applications is:
Command_1 [args] | command_2 [args]
3. Use commands to replace
In Linux Command Line mode""(Upper separator), will be executed first""Command contained in the middle, and then the output result is substituted into the command line as a parameter, which is replaced by the command.
Example: echo today isdate
Output result: today is Mon Nov 5 16:58:33 CST 2012
When nested commands are replaced, the upper delimiter must be escaped using the escape character image.
4. Comprehensive Application
After understanding and familiarizing yourself with the previous skills, it is a high skill to apply them comprehensively. Some basic and important commands frequently used in constructing LInux Commands include grep, tr, sed, awk, find, cat, and echo.
Example 1: Both output redirection and pipelines are used.
Man | col-B> manual_man
This command uses both output redirection and pipelines to save the help document of command man as a text file manual_man and filter out all control characters using option-B.
Example 2: three character-related commands, grep, tr, and awk, are used.
Catfind poem| Grep is | tr a-z A-Z | awk '{print $2}'> word
First, use the find command to find the poem file and use the grep command to find the row containing the string "is" in the file, convert all the characters in these rows into uppercase/lowercase letters in the second pipeline, and then display the second word in each line after case conversion in the third pipeline, finally, redirect the awk command output to the file word, instead of displaying the result on the screen.