Linux op-d common commands work notes

Source: Internet
Author: User
Tags html tags regular expression system log


I bought an ECS, often toss, install some good fun software, tools. Configure the LNMP environment, run the website program, very interesting. Linux is often used, so it collects and collates some Linux server operation commands

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)

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 from Cut's purpose, intercept data)

9. How to display multiple messages in the writing shell with EOF
Cat << EOF
+ ———————————————————— –+
| = = = Welcome to tunoff services = = |
+ ———————————————————— –+
Eof
10.
For the clever use (such as to build a soft link to MySQL)

Cd/usr/local/mysql/bin for i in * doing ln/usr/local/mysql/bin/$i/usr/bin/$i Done

11.
Take IP Address:
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 '} '


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} '

The 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
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

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 all log analysis results can be obtained with the # Logwatch–print–range all.
You can use # Logwatch–print–detail to get more specific log analysis results (not just error logs).

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 $ ' ' $2″n '} | Sort-n-T +0

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

Chkconfig–list | awk ' {if ($5== ' 3:on ') print '

41.kudzu View network card model
Kudzu–probe–class=network

Matching regular expressions for Chinese characters: [U4E00-U9FA5]
Commentary: Matching Chinese is really a headache, with this expression will be easy to do

Match Double-byte characters (including Chinese characters): [^x00-xff]
Commentary: can be used to compute the length of a string (a double-byte character length meter 2,ascii 1 characters)

A regular expression that matches a blank row: ns*r
Commentary: can be used to delete blank lines

Regular expression:< matching HTML tags (s*?) [^>]*>.*?</1>|<.*? />
Commentary: The online version is too bad, the above can only match the part of the complex nested tags still powerless

A regular expression that matches the end-end whitespace character: ^s*|s*$
Commentary: A useful expression that can be used to delete white-space characters (including spaces, tabs, page breaks, and so on) at the end of a line at the beginning

Regular expression matching an email address: w+ ([-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) *
Commentary: Form validation is useful

Regular expressions that match URL URLs: [a-za-z]+://[^s]*
Commentary: Online circulation of the version of the function is very limited, which can meet the basic requirements

Match account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$
Commentary: Form validation is useful

Match domestic phone number: D{3}-d{8}|d{4}-d{7}
Commentary: Match form such as 0511-4405222 or 021-87888822

Matching Tencent QQ Number: [1-9][0-9]{4,}
Commentary: Tencent QQ number starting from 10000

Match China ZIP Code: [1-9]d{5} (?! D
Commentary: China postal code is 6 digits

Matching ID: d{15}|d{18}
Commentary: China's ID card is 15-or 18-digit

Matching IP address: d+.d+.d+.d+

Commentary: Useful when extracting IP addresses

Match a specific number:
^[1-9]d*$//Matching positive integer
^-[1-9]d*$//matching negative integers
^-? [1-9]d*$//matching integer
^[1-9]d*|0$//matching nonnegative integer (positive integer + 0)
^-[1-9]d*|0$//matching non positive integer (negative integer + 0)
^[1-9]d*.d*|0.d*[1-9]d*$//matching positive floating-point numbers
^-([1-9]d*.d*|0.d*[1-9]d*) $//matching negative floating-point number
^-? ([1-9]d*.d*|0.d*[1-9]d*|0?. 0+|0) $//matching floating-point number
^[1-9]d*.d*|0.d*[1-9]d*|0? 0+|0$//matching nonnegative floating-point number (positive floating-point number + 0)
^ (-([1-9]d*.d*|0.d*[1-9]d*)) |? 0+|0$//matching non-positive floating-point numbers (negative floating-point number + 0)

Commentary: useful when dealing with large amounts of data, pay attention to corrections when applied

Match a specific string:
^[a-za-z]+$//Match a string of 26 English letters
^[a-z]+$//Match a string of 26 uppercase letters
^[a-z]+$//Match string consisting of 26 lowercase letters
^[a-za-z0-9]+$//Match a string of numbers and 26 English letters
^w+$//Match A string of numbers, 26 English letters, or underscores

Commentary: Some of the most basic and commonly used expressions

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.