Home >
OS > The combination of some commonly used commands in the Linux
The combination of some commonly used commands in the Linux
1. A directory of files and folders
A directory of files and folders number:
Ls | wc -w
A directory file file number:
The ls -l | grep "^ -" | wc -l
The number of a directory file folders:
The ls -l | grep "^ d | wc -l
Statistics of the number of files under the current folder, including subfolders in:
Ls - lR | grep "^ -" | wc -l
Wc command
-c statistics bytes,
- l statistics rows,
-m statistical characters, this flag cannot be used with the -c flag,
- w statistical word, a word is defined as blank, tabs or newline characters delimited string,
-l prints the longest line lengths,
-help display help information
- version shows version information
2. Empty a directory file (not delete the directory)
Rm - rf path to the file *
3. Check the port
The lsof -i
Lsof - I: port
Netstat tunlp | grep port
4. Check the process, kill process, kill process batch
Check the process:
Ps
Kill process:
Kill 9 pid
Batch kill process:
Ps - ef | grep test | grep -v grep | awk '{print $2} | xargs kill 9
Or:
Ps - ef | grep test | grep -v grep | the cut - 9-15 c | xargs kill 9
Among them:
| pipe, used to separate two commands, pipe the output of the command on the left will act as a pipe, the right of the command input,
The ps command to list the currently running in the system process, the ps - ef shows all process information, the allied command line,
The grep command is used to filter/search specific characters, grep test here for search filter all the processes which include the name of 'test'
Grep -v grep -v according to matching the text does not contain all the lines, to filter out everything here does not include the name of grep process, do it again on the progress of the previous step screening (because ps - ef lists all orders, including command line)
Awk rules specified in the file or a string based on browsing and extracting information; Reads the file line by line, with a space for the default delimiter in each section, and then again after the order processing, using awk '{2} print here' to filter in the previous step of process for printing, 2} 'will be in the previous step filtering process for printing, print 2 said the second domain (PID, process) 0 means all domains, 0 means all domains, 1 is the first domain, $n n a domain,
Xargs command is to pass parameters of the filter, is good at the standard data data into the command line parameters, is will get here before the standard output and then converted to a command command line arguments passed to the back of the kill command,
Kill 9 forced closure process,
In addition, also have use the cut command is processed, the reference is as follows:
Ps - ef | grep test | grep -v grep | the cut - 9-15 c | xargs kill 9
The cut - c 9-15 shows only 9-15 characters (namely the PID, process)
5. Linux how to display a few lines of a file (middle lines)
Starting line 3000, according to 1000 lines, that is, according to 3000 ~ 3999 lines
The cat filename | tail - n + 3000 | head - n 1000
Show lines 1000-3000
The cat filename | head - n 3000 | tail - n + 1000
Decomposition:
Tail - n 1000: according to the last line 1000
Tail - n + 1000: starting from the 1000 lines, shows that after 1000 lines
In front of the head - n 1000: display 1000 lines