1. Delete 0-byte files
Find-type F-size 0-exec Rm-RF {}\;
2. View Processes
Sort by memory from large to small
PS-e-o "% C: % P: % Z: % A" | sort-K5-NR
3. sort by CPU utilization from large to small
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: "$2 ;}'
5. view 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]}'
6. Sed-I '/root/S/no/Yes/'/etc/ssh/sshd_config sed: In this text, the root row matches the root row and replaces No with yes.
. How to kill the MySQL process:
PS aux | grep MySQL | grep-V grep | awk '{print $2}' | xargs kill-9 (learn about the usage of awk)
Killall-term mysqld
Kill-9 'cat/usr/local/apache2/logs/httpd. Pi'
8. Run the following three services:
Ls/etc/rc3.d/S * | cut-C 15-(learn the purpose of cut and intercept data)
9. How to display multiple pieces of information in a shell, using EOF
Cat <EOF
+ -------------------------------------------------------------- +
| === Welcome to tunoff services ===|
+ -------------------------------------------------------------- +
EOF
10. Clever Use of for (for example, creating a soft link for MySQL)
CD/usr/local/MySQL/bin
For I in *
Do ln/usr/local/MySQL/bin/$ I/usr/bin/$ I
Done
11. IP address retrieval:
Ifconfig eth0 | grep "Inet ADDR:" | awk '{print $2}' | cut-C 6-or
Ifconfig | grep 'inet ADDR: '| grep-V' 127. 0.0.1' | cut-D:-F2 | awk '{print $1 }'
12. Memory size:
Free-M | grep "mem" | awk '{print $2 }'
13.
Netstat-an-T | grep ": 80" | grep established | awk '{printf "% S % s \ n", $5, $6}' | sort
14. view 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]}'
15. my colleague wants to count the size of all JPG files under the server and write a shell to count them. it was originally implemented using xargs, but when processing part of it at a time, there are multiple sums ...., the following command can solve the problem.
Find/-name *. jpg-exec WC-C {}\; | awk '{print $1}' | awk '{A + = $1} end {print }'
The more CPUs (multi-core CPUs, CAT/proc/cpuinfo | grep-C processor), the lower the system load, the more requests that can be processed per second.
Bytes --------------------------------------------------------------------------------------------------------------------
16 CPU load # Cat/proc/loadavg
Check whether the first three output values exceed 4 times the system logic CPU.
18 CPU load # mpstat 1 1
Check whether % idle is too low (for example, less than 5%)
19. memory space # Free
You can also use # Cat/proc/meminfo to check whether the free value is too low.
20 swap space # Free
Check whether the value of swap used is too high. If the value of swap used is too high, further check whether swap actions are frequent:
# Vmstat 1 5
Check whether the Si and so values are large.
21. Disk Space # DF-H
Check whether partition usage (Use %) is too high (for example, more than 90%). If you find that a partition space is close to exhausted, you can enter the mount point of the partition, run the following command to find the most occupied files or directories:
# 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 whether the network traffic (rxbyt/s, txbyt/s) is too high.
24 network errors # netstat-I
Run the following command to check whether a network error exists (drop FIFO colls carrier): # Cat/proc/NET/dev
25 network connection count # netstat-an | grep-e "^ (TCP)" | cut-C 68-| sort | uniq-c | sort-n
26 processes # ps aux | WC-l
Check whether the number of processes is normal (for example, more than 250)
27. Number of processes that can be run # vmwtat 1 5
The column shows the number of processes that can be run. Check whether the number exceeds 4 times the system logic CPU.
28 process # top-Id 1
Check for abnormal Processes
29 check whether the network status can be properly connected, such as DNS and gateway.
30 users # Who | WC-l
Run the following command to check whether there are too many login users (for example, more than 50): # uptime
31 system logs # Cat/var/log/rflogview/* errors
You can also search for some exception keywords to check whether there are any error records, for example:
# Grep-I error/var/log/messages
# Grep-I fail/var/log/messages
32 core logs # dmesg
Check for abnormal error records
33 system time # date
Check whether the system time is correct
34. Number of opened files # lsof | WC-l
Check whether there are too many open files
35 logs # logwatch-print configuration/etc/log. d/logwatch. conf: Set mailto to your own email address and start the mail service (sendmail or Postfix) so that you can receive the log report every day.
By default, logwatch only reports logs of yesterday. You can use # logwatch-print-range all to obtain all log analysis results.
You can use # logwatch-print-Detail high to obtain more specific log analysis results (not just error logs ).
36. Kill the process related to port 80
Lsof-I: 80 | grep-V "PID" | awk '{print "Kill-9", $2}' | sh
37. Clear dead processes.
PS-eal | awk '{if ($2 = "Z") {print $4}' | kill-9
38. tcpdump: capture packets to prevent attacks on port 80.
# Tcpdump-C 10000-I eth0-N DST port 80>/root/Pkts
39. Check the number of IP duplicates and sort them in ascending order. Note that there are two spaces in the middle of "-T \ + 0 ".
# Less Pkts | awk {'printf $3 "\ n" '} | cut-D. -F 1-4 | sort | uniq-c | awk {'printf $1 "" $2 "\ n" '} | sort-n-t \ + 0
40. view the number of active PHP-CGI Processes
Netstat-anp | grep PHP-CGI | grep ^ TCP | WC-l
Chkconfig -- list | awk '{if ($5 = "3N") Print $1 }'
41. view the NIC model in Kudzu
Kudzu -- Probe -- class = Network