Linux Classic Shell command finishing __linux

Source: Internet
Author: User
Tags system log iptables varnish

Http://www.ha97.com/4021.html

1. Delete 0-byte files
Find-type f-size 0-exec rm-rf {};

2. View process
Arrange 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 in this text a row of root, matching the root row, replace No to 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 to check process PID

8. Show the service that is running level 3 not open:
ls/etc/rc3.d/s* |cut-c 15-

(Learn about Cut's purpose, intercept data)

9. How to display multiple messages in the writing shell with EOF
Cat << EOF
+--------------------------------------------------------------+
| = = = Welcome to tunoff services = = |
+--------------------------------------------------------------+
Eof

For the skillful use (such as to build a soft link to MySQL)
Cd/usr/local/mysql/bin
For i in *
Do 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 obtaining IP:
ifconfig-a | Perl-ne ' if (m/^s*inet (?: Addr:)? [D.] +). *?cast/) {print QQ ($1n); exit 0;} '

12. Size of Memory:
Free-m |grep "Mem" | awk ' {print $} '

13.
netstat-an-t | grep ": 80" | grep established | awk ' {printf '%s%sn ', $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 the server below all the jpg file size, wrote a shell to him to statistics. Originally used Xargs to achieve, but he dealt with a part of the sum of a number of ..., the following command can be solved.
Find/-name *.jpg-exec wc-c {}; |awk ' {print} ' |awk ' {A+=$1}end{print A} '

Number of CPUs (multiple CPUs are accounted for,
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
Check that the top three output values exceed 4 times times the system logic CPU.

CPU Load #mpstat 1 1
Check if%idle is low (for example, less than 5%)

19 Memory Space # FREE
Check free value is too low can also use # Cat/proc/meminfo

Free Space #
Check to see if the swap used value is too high if the swap used is too high, check for frequent swap actions:
# vmstat 1 5
See if Si and so values are larger

21 Disk Space # Df-h
Check if zoning usage (use%) is too high (e.g. over 90%) If a partition is found to be nearly exhausted, you can go to the mount point of the partition to locate the file or directory that occupies the most space by using the command:
# Du-cks * | Sort-rn | Head-n 10

22 disk I/O load # iostat-x 1 2
Check I/O usage (%util) is over 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) can also be ordered: # Cat/proc/net/dev

25 Number of Network Connections # Netstat-an | Grep-e "^ (TCP)" | Cut-c 68-| Sort | uniq-c | Sort-n

26 Process Total # PS aux | Wc-l
Check if the number of processes is normal (for example, more than 250)

27 Number of processes to run # vmwtat 1 5
The column gives the number of running processes, checking to see if they exceed 4 times times the system logic CPU

28 Process # top-id 1
Observe if an exception process appears

29 Network status Check DNS, gateways, etc. can be properly connected

30 Users # who | Wc-l
Check if there are too many logged in users (for example, more than 50) can also use the command: # uptime

31 System Log # Cat/var/log/rflogview/*errors
Check for unusual error records to search for 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 exceptions
32 Core Log # DMESG
Check for abnormal error logging

33 System Time # Date
Check that the system time is correct

34 Number of open files # Lsof | Wc-l
Check whether the total number of open files is too large

35 Days Log # Logwatch? Print configuration/etc/log.d/logwatch.conf, set Mailto to its own email address, start mail Service (SendMail or postfix), so you can receive a daily journal report.
The default Logwatch only reports yesterday's logs, and you can get all the log analysis results with the # Logwatch print range all.
You can get more specific log analysis results (not just error logs) with # Logwatch print Detail high.

36. Kill 80-Port-related processes
Lsof-i: 80|grep-v "PID" |awk ' {print ' Kill-9 ", $} ' |sh

37. Clear Zombie process.
Ps-eal | awk ' {if ($ = = ' Z ') {print $}} ' | Kill-9

38.tcpdump grab bag, used to prevent 80-port from being attacked can analyze data.
# tcpdump-c 10000-i eth0-n DST port >/root/pkts

39. Then check the number of IP repeats and small to large sort of note "-t +0″ in the middle of 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

40. See how many php-cgi processes are active
NETSTAT-ANP | grep php-cgi | grep ^tcp | Wc-l

41. Using 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 { 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 part of the set value for the threshold, this sentence will automatically be found in the Netstat-an from the same IP over a certain number of connections from the inclusion of the prohibited range. Kizhong native IP to the IP address of your server

42. How to know which CPU a process is running on.
# Ps-eo PID,ARGS,PSR

43. View hardware Manufacturers
Dmidecode-s System-product-name

44.perl how to compile bytecode so that it is quicker to handle complex projects.
Perlcc-b-O webseek webseek.pl

45. The statistics in the var directory file with M as the size, listed in the form of a list.
Find/var-type F | Xargs Ls-s | Sort-rn | awk ' {size=$1/1024; printf ("%dMb%sn", size,$2);} ' | Head
Find files with 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 server Manufacturer
Dmidecode-s System-product-name

Wget Simulate 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 under the statistics directory (printed by M)
Du $1–max-depth=1 | Sort-n|awk ' {printf '%7.2fm-->%sn ', $1/1024,$2} ' |sed ' s:/.*/([^/]{1,}) $:1:g '

51. Implementation of several relevant statistics on CND
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 all subdirectories in a directory
Find./-type D-print | Wc-l

To count the size of a type of file:
Find./-name "*.jpg"-exec wc-c {}; |awk ' {print} ' |awk ' {A+=$1}end{print A} '

53. Find the processes that occupy 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 in 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 Condition:
Dmidecode |grep-p "Maximums+capacity"

Maximum Machine support Memory:
Dmidecode |grep-p "Maximums+capacity"

57. View total memory consumed by php-cgi:
Total=0 to I in ' ps-c php-cgi-o rss= '/Do total=$ (($total + $i)), done; echo "php-cgi Memor Y usage: $total KB "

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.