In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the commonly used shell commands in Linux system management", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the commonly used shell commands in Linux system management"?
1. Displays the top 10 processes consuming memory / CPU
The code is as follows:
Ps aux | sort-nk + 4 | tail
Ps aux | sort-nk + 3 | tail
two。 View the process
Sort by memory from large to small
The code is as follows:
Ps-e-o "% C:% p:% z:% a" | sort-K5-nr
3. Ranked by cpu utilization from large to small
The code is as follows:
Ps-e-o "% C:% p:% z:% a" | sort-nr
3. Check the number of concurrent requests for Apache and their TCP connection status
The code is as follows:
Netstat-n | awk'/ ^ tcp/ {+ + S [$NF]} END {for (an in S) print a, S [a]}'
4. Find the processes that consume the most disk IO
The code is as follows:
Wget-c http://linux.web.psi.ch/dist/scientific/5/gfa/all/dstat-0.6.7-1.rf.noarch.rpm
Dstat-M topio-d-M topbio
5. Find out the 10 most commonly used commands and the number of times they are used (or the number of ip visited most)
The code is as follows:
Sed-e's / | /\ nnr g'~ / .bash_history | cut-d'- f 1 | sort | uniq-c | sort-nr | head
6. The 10th field in the log indicates the connection time and calculates the average connection time
The code is as follows:
Cat access_log | grep "connect cbp" | awk 'BEGIN {sum=0;count=0;} {sum+=$10;count++;} END {printf ("sum=%d,count=%d,avg=%f\ n", sum,count)
Sum/count)}'
7.lsof command
Lsof abc.txt shows the process of opening the file abc.txt
Lsof-I: 22 know what program port 22 is running now
Lsof-c abc displays the files now opened by the abc process
Lsof-p 12 to see which files are opened by the process with process number 12
8.rsync command (requires only the compressed files for a certain day to be synchronized, and the remote directory remains the same as the local directory)
The code is as follows:
/ usr/bin/rsync-azvR-password-file=/etc/rsync.secrets `find. -name "* $yesterday.gz"-type f `storage@192.168.2.23::logbackup/13.21/
9. Rename the * .sh file in the directory to * .SH
The code is as follows:
Find. -name "* .sh" | sed's /\ (. *\)\ .sh / mv\ 0\ 1.SH'| sh
Find. -name "* .sh" | sed's /\ (. *\)\ .sh / mv &\ 1.SHUnip'| sh (same as the effect above)
10.ssh executes remote programs and displays them locally
The code is as follows:
Ssh-n-l zouyunhao 192.168.2.14 "ls-al / home/zouyunhao"
11.shell segment comments
The code is as follows:
: 8 the partial setting value is a threshold, and this sentence automatically forbids more than a certain number of connections from the same IP found in netstat-an. Change the local ip to the ip address of your server
forty-two。 How do I know which CPU a process is running on?
The code is as follows:
# ps-eo pid,args,psr
forty-three。 Statistics var directory files with M as the size, listed in the form of a list.
The code is as follows:
Find / var-type f | xargs ls-s | sort-rn | awk'{size=$1/1024; printf ("% dMb% s\ n", size,$2);}'| head
Look for files with files larger than 100m in the var directory, and count the number of files
The code is as follows:
Find / var-size + 100m-type f | tee file_list | wc-l
forty-four。 Sed finds and replaces content
The code is as follows:
Sed-I "s/varnish/LTCache/g" `grep "Via"-rl / usr/local/src/varnish- 2.0.4`
Sed-I "s/X-Varnish/X-LTCache/g" `grep "X-Varnish"-rl / usr/local/src/varnish- 2.0.4`
forty-five。 Count the size of the files in the directory (printed by M)
The code is as follows:
Du $1-- max-depth=1 | sort-n | awk'{printf "% 7.2fM->% s\ n", $1DB 1024 7.2fM 2}'| sed's awk /\ ([^ /]\ {1,\}\) $:\ 1g sort'
forty-six。 Several related Statistics about CND implementation
Count the number of directories in a directory
The code is as follows:
Ls-l | awk'/ ^ dplink'| wc-l
Count the number of files in a directory
The code is as follows:
Ls-l | awk'/ ^-/'| wc-l
Count all the files in a directory
The code is as follows:
Find. /-type f-print | wc-l
Count all the subdirectories in a directory
The code is as follows:
Find. /-type d-print | wc-l
Count the size of certain types of files:
The code is as follows:
Find. /-name "* .jpg"-exec wc-c {}\; | awk'{print $1}'| awk'{print a}'
forty-seven。 Remove the first column (e. G. line number code)
The code is as follows:
Awk'{for ($1 Universe 20, "M"): $1 > = 2 cycles 10? ($1 Universe 2 cycles 10, "K"): ($1, "K"): (1, ")} e'
Shaw answer: du-hs $(du-sk. / `ls-F | grep / `| sort-nr | awk'{print $NF}')
It can also be realized, but it is not perfect. But easy to remember.
fifty-two。 Clear linux buffer cache
The code is as follows:
Sync & & echo 3 > / proc/sys/vm/drop_caches
fifty-three。 Converts all current directory file names to lowercase
The code is as follows:
For i in *; do mv "$I"$(echo $I | tr Amurz)"; done
fifty-three。 Several methods of eliminating ^ M in vim
1) dos2uninx filename
2) sed-e's / ^ M / / 'filename
3) in vim: s / ^ M / / gc
4) col-bx
< dosfile >Newfile
5) tr-s "\ r\ n"\ n"
< file >Newfile
fifty-four。 Clear all arp caches
The code is as follows:
Arp-n | awk'/ ^ [1-9] / {print "arp-d" $1}'| sh
fifty-five。 Bind the arp address of a known machine
The code is as follows:
Cat / proc/net/arp | awk'{print $1 "" $4}'| sort-t. -n + 3-4 > / etc/ethers
Perl's
The code is as follows:
Perl-ne m / ^ ([^ #] [^\ s =] +)\ s* (=. * |) / & & printf ("%-35s%s\ n", $1, $2)'/ etc/my.cnf
fifty-five。 Check the ip and number of attacks of ssh brute force attacks
The code is as follows:
Grep-o'[0-9]\ {1 uniq 3\}\. [0-9]\ {1 uniq 3\}\. [0-9]\ {1 recorder 3\}\. [0-9]\ {1 recorder 3\}'/ var/log/secure | sort | uniq-c
At this point, I believe that everyone has a deeper understanding of "what shell commands are commonly used in Linux system management". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.