Senior Linux command-line skills

  The Linux command line has powerful features for skilled Linux system administrator, often only needs through a variety of techniques, the combination constitutes a complex command, thus completing the user tasks.
  
  Then a complex Linux commands what constitutes it? Here to introduce a few tips.
  
Using the input / output redirection 
  In the Linux command line mode, if the output is not required command from the keyboard, but from the specified file, which is the input redirection. Similarly, the output of the command may not be displayed on the screen, but is written to the specified file, which is the output redirection.
  
  Then take a look at the practical application of the standard input / output redirection in the construction of a Linux command.
  
   1. redirect input and output redirection 
  # wc home.txt
  
  The first command as input file aa.txt wc command, the statistics aa.txt number of lines, words, and characters. The second command output of the ls command is saved in a file named home.txt in. If the> symbol behind the file already exists, then the file will be overwritten.
  
   2. The use of input and output redirection 
  # iconv -f gb18030 -t utf-8 new-aa.txt
  
  This command is used in the same time the input redirection (new-aa.txt). aa.txt gb18030 actually a coded file, the contents of new-aa.txt aa.txt sucked into a new file utf-8 format.
  
Using the pipeline
  Linux using the pipe symbol provided by the "|" two commands separated by pipe character to the left output of the command will be used as input pipe symbol to the right of command. Continuous use of pipelines means that the first command will output the second command as input, the output of the second command will enter as the third command, and so on. Let's look at how the pipeline is to be applied in the construction of a Linux command.
  
   1. The use of a pipe
  # Rpm -qa | grep licq
  
  This command uses a pipe symbol "|" has established a pipeline. The output conduit rpm -qa command (including all installed RPM package system) as input grep command to list the RPM package with characters to licq.
   2. The use of a plurality of pipes
  
  # cat /etc/passwd | grep /bin/bash | wc -l
  
  
  This command uses two pipes, a first pipe using the cat command (display contents passwd file) to the output grep command, grep command to find all rows containing "/ bin / bash"; the second duct the grep input gave wc command, wc command the statistics of the number of lines in the input. The function of this command is to find out how many users the system to use bash.
  
Use command substitution
  In the Linux command line, when met a "` "(delimiter on), the first command" `" intermediate contains, and then outputs the result as parameters into the command line, which is the command replaces the . It is similar to the input and output redirection, but with the difference that the replacement command is a command output as a parameter of another command. Here we look at its practical application.
  
   1. Use the command substitution
  # touch `date +%Y%m%d%k%M%S`.txt
  
  The command uses a command substitution, date +% Y% m% d% k% M% S will be executed first command, it outputs the current format specified time. Then the time will be used as the parameter touch command, the result is the establishment of a current time for the file name of the file.
  
   2. Use command substitution 
  # kill `/sbin/pidof smbd`
  
  This command will kill all the sshd process. Here is the process number pidof with this command, because kill is operated for the process ID. Both command substitution achieved with only one command to kill all processes sshd function.
  
Integrated application 
  After understanding and familiarity with the previous few tips, they are together is the integrated use of the higher skills. At the same time, some common, and the usage itself is more complex Linux commands must master. Some basic and important command in the Linux command structure often used have grep, tr, sed, awk, find, cat and echo, etc. Let's look at some examples of integrated applications.
  
  1.
  
  # man ls | col -b > ls.man.txt
  
  This command while the use of output redirection and pipes two techniques, the role is to help ls turn information into a text file that can be read directly.
  
  2.
  
  # kill -9 `ps -ef | grep smbd | tr -s ' ' | awk -F' ' '{print $2}'`
  
  The above features and functionality of this example is the same, but it does not depend pidof command, using the most Unix-like systems have orders for more systems environment. However, it looks more complicated, three pipes and a command substitution, additionally used grep, tr and awk three characters associated with the operation command.
  
  As can be seen from the foregoing description, by a combination of several techniques, Linux commands can perform complex functions. In addition, these commands can be organized into a script in the past, plus function variables, judgments, and circulation and other functions, and then add some programming ideas, is more powerful Shell scripts.

Reproduced in: https: //www.cnblogs.com/Leon5/archive/2009/11/29/1612941.html

Guess you like

Origin blog.csdn.net/weixin_33709609/article/details/93948129