Linux Classic Shell command collation
1. Delete a 0-byte file
Find-type f-size 0-exec rm-rf {} \;
2. View the process
Sort by memory from large to small
PS-E-O "%c:%p:%z:%a" |sort-k5-nr
3. By CPU utilization from large to small arrangement
PS-E-O "%c:%p:%z:%a" |sort-nr
4. Print the URL in the cache
Grep-r-a jpg/data/cache/* | Strings | grep "http:" | Awk-f ' http: ' {print ' http: ' $ ';} '
5. View the number of concurrent requests for HTTP and their TCP connection status:
Netstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} '
6.
Sed-i '/root/s/no/yes/'/etc/ssh/sshd_config sed the root line in this article, match the root line and replace no with Yes.
7.1. How to kill the MySQL process:
PS aux|grep mysql|grep-v Grep|awk ' {print $} ' |xargs kill-9
(Learn about the use of awk)
Pgrep MySQL |xargs kill-9
Killall-term mysqld
Kill-9 ' Cat/usr/local/apache2/logs/httpd.pid '
Try the Avira process PID
8. Display the services that are running Level 3 open:
ls/etc/rc3.d/s* |cut-c 15-
(Learn the purpose of cut, intercept data)
9. How to display multiple messages in the writing shell, with EOF
Cat << EOF +--------------------------------------------------------------+ | = = = Welcome to tunoff services = = = | +--------------------------------------------------------------+ EOF 10. For a clever use (such as to build a soft link to MySQL) cd/usr/local/mysql/bin for i in * does ln/usr/local/mysql/bin/$i/usr/bin/$i done 11. Take IP address: ifconfig eth0|sed-n ' 2p ' |awk ' {print $} ' |cut-c 6-30 or: ifconfig eth0 |grep ' inet addr: ' |awk ' {print $} ' |cut- C 6-or Ifconfig | grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' | Cut-d:-f2 | awk ' {print '} ' or: Ifconfig eth0 | Sed-n '/inet/{s/.*addr://;s/. *//;p} ' Perl implements the method of acquiring IP: ifconfig-a | Perl-ne ' if (m/^\s*inet (?: Addr:)? ( [\d.] +). *?cast/) {print QQ ($1\n); exit 0;} ' 12. Memory Size: free-m |grep "Mem" | awk ' {print $13} '. netstat-an-t | grep ": 80" | grep established | awk ' {printf '%s%s\n ", $5,$6} ' | Sort 14. View the number of concurrent requests for Apache and its TCP connection status: Netstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} ' 15. Because colleagues want to count all the files under the server JPG file size, wrote a shell for him to count. It was originally implemented in Xargs, but he dealt with it one at a time. , there are a number of sums ...., the following command can be solved. Find/-name *.jpg-exec wc-c {} \;|awk ' {print $} ' |awk ' {a+=$1}end{print A} ' number of CPUs (multiple CPU, Cat/proc/cpuinfo |grep- C processor more, the lower the system load, the more requests can be processed per second. --------------------------------------------------------------------------------------------------------------- -----CPU Load # CAT/PROC/LOADAVG checks whether the first three output values exceed 4 times times the system logical CPU. CPU Load #mpstat 1 1 Check if the%idle is too low (for example, less than 5%) 19 Memory Space # FREE Check if the value is too low to use # Cat/proc/meminfo swap space # to check if the swap used is too high if the swap used value is too high, check for frequent swap actions: # VM Stat 1 5 See if Si and so values are larger 21 disk space # DF-H Check for partition utilization (use%) too high (for example, more than 90%) If a partition space is found to be nearly exhausted, you can go to the mount point of the partition and use the following command to find the file or directory that occupies the most space: # Du-cks * | Sort-rn | Head-n 10 22 disk I/O load # iostat-x 1 2 Check if I/O usage (%util) exceeds 100% 23 Network Load # sar-n DEV Check network traffic (rxbyt/s, txbyt/s) is too high 24 network error # Netstat-i Check for network errors (drop FIFO colls carrier) also available with command: # Cat/proc/net/dev 25 Number of network Connections # Netstat-an | Grep-e "^ (TCP)" | Cut-c 68-| Sort | uniq-c | Sort-n 26 Processes Total # PS aux | WC-L Check whether the number of processes is normal (for example, more than 250) 27 number of running processes # vmwtat 1 5 column gives the availableNumber of row processes, check whether it exceeds the system logical CPU 4 times times 28 Process # top-id 1 See if there is an exception process appears 29 network status check DNS, gateway, etc. can connect properly 30 users # who | WC-L Check whether the logged-on user is too many (for example, more than 50) can also use the command: # Uptime 31 System Log # Cat/var/log/rflogview/*errors check for abnormal error records can also search for some exception keywords, such as: # Grep-i Error/var/log/messages # grep-i Fail/var/log/messages # egrep-i ' Error|warn '/var/log/messages View system exception 32 core Log # DMESG Check for abnormal error logging 33 system Time # Date Check the system time is correct 34 number of open files # Lsof | Wc-l Check if the total number of open files is too many 35 days log # Logwatch? Print configuration/etc/log.d/logwatch.conf, set Mailto to its own email address, start the mail service (SendMail or Postfix) So that you can receive a log report every day. The default Logwatch only reports yesterday's log, you can use # Logwatch? print? Range all to get all the log analysis results. You can use # Logwatch print? Detail high to get more specific log analysis results (not just error logs). 36. Kill the 80-port related process lsof-i: 80|grep-v "PID" |awk ' {print ' kill-9 ', $ $} ' |sh 37. Clear the Zombie process. Ps-eal | awk ' {if ($ = = "Z") {print $4}} ' | Kill-9 38.tcpdump Grab packet to prevent 80 port from being attacked when you can analyze data # tcpdump-c 10000-i eth0-n DST port >/root/pkts
39. Then check the number of repetitions of IP and order from small to large note "-t\ +0″ the middle is two spaces
# less Pkts | awk {' printf $3″\n '} | Cut-d.-F 1-4 | Sort | uniq-c | awk {' printf $ ' "$2″\n" '} | Sort-n-t\ +0
40. See how many php-cgi processes are active
NETSTAT-ANP | grep php-cgi | grep ^tcp | Wc-l
41. Use Iptables to respond to simple attacks
Netstat-an | Grep-v LISTEN | awk ' {print $} ' |grep-v 127.0.0.1|grep-v native ip|sed ' s/::ffff://g ' |awk ' BEGIN {fs= ': '} {num[$1]++} END {for (I in Num if (num>8) {print i}} ' |grep ' [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\} ' | xargs-i[] Iptables-i input-s []-j DROP
Num>8 partial setpoint is the threshold value, this sentence will automatically be found in the Netstat-an from the same IP over a certain amount of connection to the prohibited range. Kizhong native IP to the IP address of your server
42. How do I know which CPU a process is running on?
# Ps-eo PID,ARGS,PSR
43. View the hardware manufacturer
Dmidecode-s System-product-name
How can 44.perl be compiled into bytecode so that it is faster when dealing with complex projects?
Perlcc-b-O webseek webseek.pl
45. In the Statistics var directory, the files are listed as a list in M size.
Find/var-type F | Xargs Ls-s | Sort-rn | awk ' {size=$1/1024; printf ("%dMb%s\n", size,$2);} ' | Head
Find files larger than 100M in the Var directory, and count the number of files
Find/var-size +100m-type F | Tee File_list | Wc-l
. sed find and replace content
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 '
47. View the server manufacturer
Dmidecode-s System-product-name
wget Analog user-agent Crawl Web page
Wget-m-E Robots=off-u "mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.1.6) gecko/20091201 firefox/3.5.6 "http://www.example.com/
50. The size of the file in the statistics directory (printed by M)
Du $1–max-depth=1 | Sort-n|awk ' {printf '%7.2fm-->%s\n ", $1/1024,$2} ' |sed ' s:/.*/\ ([^/]\{1,\}\] $:\1:g ')
51. About CND implementation of several related statistics
Count the number of directories in a directory
Ls-l | awk '/^d/' | Wc-l
Count the number of files in a directory
Ls-l | awk '/^-/' | Wc-l
Count the total number of files in a directory
Find./-type F-print | Wc-l
Count the total number of subdirectories in a directory
Find./-type D-print | Wc-l
To count the size of a class of files:
Find./-name "*.jpg"-exec wc-c {} \;|awk ' {print $} ' |awk ' {A+=$1}end{print A} '
53. Find the process that consumes the most disk IO
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
54. Remove the first column (e.g. line number code)
awk ' {for (i=2;i<=nf;i++) if (i!=nf) {printf $i ""}else{print $i}} ' list 55. Output 256 color for i in {0..255}; Do echo-e "\e[38;05;${i}m${i}", done | column-c 80-s "; echo-e" \e[m "56. View machine support memory machine plug Memory: Dmidecode |grep-p" Maxim Um\s+capacity "Machine max Memory: Dmidecode |grep-p" Maximum\s+capacity "57. View total memory occupied by php-cgi: total=0; For i in ' ps-c php-cgi-o rss= '; Do total=$ (($total + $i)); Done echo "php-cgi Memory usage: $total KB" Netseek Source: http://bbs.linuxtone.org/thread-16-1-1.html
Classic shell command collation for Linux