1. Delete 0-byte files

find -type f -size 0 -exec rm -rf {} \; `Copy the code

2. View processes in order of memory

PS -e -o "%C : %p : %z : %a"|sort -k5 -nr
Copy the code

3, in order of CPU utilization

ps -e -o "%C : %p : %z : %a"|sort -nr
Copy the code

4. Print the CACHE URL

grep -r -a jpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2; } 'Copy the code

Query the number of concurrent HTTP requests and their TCP connection status:

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
Copy the code

Sed -i ‘/root/s /no/yes/’ /etc/ssh/sshd_config sed -i’ /root/s /no/yes/’ /etc/ssh/sshd_config sed

How to kill the MySQL process

Ps aux | grep mysql | grep -v grep | awk '{print $2}' | xargs kill 9 (learn to awk utility) killall - TERM mysqld kill 9 ` cat / usr/local/apache2 / logs/HTTPD pid ` try killing process pidCopy the code

Run level 3 enabled services:

Ls/etc/rc3. D/S * | the cut - c - 15 (see to the purpose of the cut, interception of data)Copy the code

9. How to display multiple messages in a SHELL using EOF

cat << EOF
+--------------------------------------------------------------+
|       === Welcome to Tunoff services ===                |
+--------------------------------------------------------------+
EOF
Copy the code

MySQL > create soft link for MySQL > create soft link for MySQL

cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done
Copy the code

11. Obtain the IP address

The ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | the cut - 6 - c or ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | the cut  -d: -f2 | awk '{ print $1}'Copy the code

12, memory size:

free -m |grep "Mem" | awk '{print $2}'
Copy the code

13

netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort
Copy the code

Query the number of concurrent Apache requests and their TCP connection status:

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
Copy the code

15, because the colleague wants to count the size of all the JPG files below the server, wrote a SHELL to him to count. Originally implemented with XARgs, but it handles one part at a time. There are multiple summations… The following command will solve the problem.

find / -name *.jpg -exec wc -c {} \; |awk '{print $1}'|awk '{a+=$1}END{print a}'Copy the code

More than the number of cpus (accounting multiple cpus, the cat/proc/cpuinfo | grep -c processor), the more the lower the system load, can deal with is, the more the number of requests per second.

16. CPU load

cat /proc/loadavg
Copy the code

Check if the first three output values exceed 4 times the system logical CPU.

17. CPU load

mpstat 1 1
Copy the code

Check whether %idle is too low (e.g., less than 5%).

18. Memory space

free
Copy the code

To check if free is too low, you can also use # cat /proc/meminfo

19. SWAP space

free
Copy the code

Check whether the swap used value is too high. If the swap used value is too high, check whether the swap action is frequent.

vmstat 1 5
Copy the code

Observe whether the SI and SO values are large

20. Disk space

df -h
Copy the code

Check whether the Use% of a partition is too high (for example, over 90%). If the space of a partition is nearly used up, go to the mount point of the partition and run the following command to find the files or directories that occupy the most space:

du -cks * | sort -rn | head -n 10
Copy the code

21. Disk I/O load

iostat -x 1 2
Copy the code

Check whether the I/O usage (%util) exceeds 100%

22. Network load

sar -n DEV
Copy the code

Check whether the network traffic (RXBYT /s, TXBYT /s) is too high

23. Network error

netstat -i
Copy the code

Check for network errors (drop FIFo colls carrier) by using the # cat /proc/net/dev command

24. Number of network connections

Netstat - an | grep -e "^" (TCP) | the cut - 68 - c | sort | uniq -c | sort - nCopy the code

25. Total number of processes

ps aux | wc -l
Copy the code

Check whether the number of processes is normal (for example, more than 250)

26. Number of runnable processes

vmwtat 1 5
Copy the code

Column gives the number of runnable processes, checking to see if they exceed 4 times the system logical CPU

27, processes,

top -id 1
Copy the code

Observe for abnormal processes.

28, network status, check whether DNS, gateway and other normal connectivity

29, user

who | wc -l
Copy the code

You can also check if there are too many logins (say more than 50) using the command # uptime.

30. System logs

# cat /var/log/rflogview/*errors
Copy the code

Check for exception errors. You can also search for exception keywords, such as:

grep -i error /var/log/messages
grep -i fail /var/log/messages
Copy the code

31. Core logs

dmesg
Copy the code

Check whether abnormal errors are recorded.

32. System time

date
Copy the code

Check whether the system time is correct.

33. Number of open files

lsof | wc -l
Copy the code

Check whether the total number of open files is too large.

34, logs,

# logwatch - printCopy the code

Configure /etc/log.d/logwatch.conf, set Mailto to your email address, and start the mail service (sendmail or postfix) so that you can receive log reports every day. By default, logwatch reports only yesterday’s logs. You can use # logwatch — print — range all to get all log analysis results. You can use # logwatch — print — detail high to get more specific log analysis results (rather than just error logs). 35. Kill the processes associated with port 80

Lsof - I: 80 | grep -v "ID" | awk '{print "kill 9", $2}' | shCopy the code

Clear dead processes

ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9
Copy the code

Tcpdump packet capture is used to prevent port 80 from being attacked and analyze data

tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts
Copy the code

38, Then check the number of IP repeats and sort them from smallest to largest. Note that “-t\ +0” is separated by two Spaces

# less pkts | awk {'printf $3"\n"'} | cut -d. -f 1-4 | sort | uniq -c | awk {'printf $1" "$2"\n"'} | sort -n -t\ +0
Copy the code

Check how many active PHP-CGI processes there are

netstat -anp | grep php-cgi | grep ^tcp | wc -l
Copy the code

40. View the automatic startup service

chkconfig --list | awk '{if ($5=="3:on") print $1}'
Copy the code

41. Kudzu Check the NIC model

kudzu --probe --class=network
Copy the code

Common regular expressions

[u4e00-u9fa5] [u4e00-u9fa5]

Note: Matching Chinese is really a headache, with this expression is easy to do

2. Match double-byte characters (including Chinese characters) : 1

Note: Can be used to calculate the length of a string (2 for a double-byte character, 1 for ASCII characters)

3. Regular expressions that match blank lines: \n\s*\r

Comment: Can be used to delete blank lines

4. Regular expressions that match HTML tags: <(\S

?). 2

>.

? < 1 > / \ | <.

? />

Note: The version circulating on the Internet is so bad that this one only matches parts and is still useless for complex nested tags

5. Regular expression that matches the first and last whitespace characters: ^\s

|\s

$

Comment: a useful expression that can be used to remove whitespace (including Spaces, tabs, page feeds, and so on) at the beginning and end of a line

6. Regular expressions matching Email addresses:

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Copy the code

Note: Useful for form validation

[A-za-z]+://3*

Comments: the version circulating on the Internet is very limited in function, the above one can basically meet the needs

8. Check whether the matching account is valid (starting with a letter, allowing 5-16 bytes, alphanumeric underscores) :

^ [a zA - Z] [a - zA - Z0-9 _] {4, 15} $Copy the code

Note: Useful for form validation

9. Match the domestic telephone number: \ d {3} – \ d {8} | \ d {4} – \ d {7}

Comments: The matching form is 0511-4405222 or 021-87888822

10. Match Tencent QQ id: 1-9{4,}

Comments: Tencent QQ number starts from 10000

11. Match Chinese zip code: [1-9]\d{5}(? ! \d)

Note: China postcodes are 6 digits

12. The matching XXX: \ d {15} | \ d {and}

Comments: Chinese ××× is the 15th or 18th place

13. Match the IP address: \d+.\d+.\d+

Note: It is useful for extracting IP addresses

14. Match a specific number:

^[1-9]\d*$// Matches positive integer ^-[1-9]\d*$// Matches negative integer ^-? \ [1-9] d * $^ / / matching integer \ [1-9] d * | 0 $/ / match non-negative integer (positive integer + 0) ^ - [1-9] \ | 0 $d * / / match the positive integer (negative integers + 0) ^ 1 - [9] \ d * \ \ d * \ | 0. [1-9] \ d \ d * * $/ / match is floating point ^ - (1-9] [\ d * \ \ d * \ | 0. [1-9] \ d \ d * *) $/ / take floating-point ^ - match? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0? \. | 0 + 0) $/ / match floating-point ^ [1-9] \ d * \ \ d * \ | 0. [1-9] \ d \ d * * | 0? \. | 0 0 + $/ / match nonnegative floating-point Numbers (is floating point number + 0) ^ (- (1-9] [\ d * \ \ d * \ | 0. [1-9] \ d \ d * *)) | 0? \. | 0 0 + $/ / match is a floating point number (negative floating-point number + 0)Copy the code

Comments: useful when dealing with a large amount of data, pay attention to the revision of specific applications

15. Match a specific string:

^[A-za-z]+$// Matches A string of 26 letters ^[A-z]+$// Matches A string of 26 letters in upper case ^[A-z]+$// Matches A string of 26 letters in lower case ^[A-zA-z0-9]+$// Matches A string consisting of digits and 26 letters. ^\w+$// Matches A string consisting of digits, 26 letters, or underscoresCopy the code

Comments: Some of the most basic and commonly used expressions