Summary of 40 necessary commands for Linux operation and maintenance

Ma Nong Online 2021-01-21 14:05:08
summary necessary commands linux operation


Linux Necessary for operation and maintenance 40 A command summary sharing
1、 Delete 0 Byte file
Linux Study

find -type f -size 0 -exec rm -rf {} \;

2、 Check the process

Sort by memory from large to small

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

3、 Press CPU The utilization is arranged from large to small

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

4、 Print cache Inside URL

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

5、 see http The number of concurrent requests and TCP Connection status :

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

6、sed In this article Root A line , matching Root a line , take no Replace with yes

sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config 

7、 How to kill MySQL process

ps aux |grep mysql |grep -v grep |awk '{print $2}' |xargs kill -9 ( Learn from it awk Use of )killall -TERM mysqldkill -9 `cat /usr/local/apache2/logs/httpd.pid` # Try the killing process PID

8、 Show run 3 Level enabled services :

ls /etc/rc3.d/S* |cut -c 15- ( Learn from it cut Use of , Intercept data )

9、 How to write SHELL Show multiple messages , use EOF

cat << EOF+--------------------------------------------------------------+| === Welcome to Tunoff services === |+--------------------------------------------------------------+EOF

10、for The ingenious use of ( If given MySQL Build soft links )

cd /usr/local/mysql/binfor i in *do ln /usr/local/mysql/bin/$i /usr/bin/$idone

11、 take IP Address

ifconfig eth0 |grep "inet addr:" |awk '{print $2}'| cut -c 6-

perhaps

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}'13netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort

14、 see Apache The number of concurrent requests and 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 servers jpg The size of the file , Wrote a SHELL Give him statistics . Original use xargs Realization , But he deals with part of it at a time . There are many sums of things ……, The following command will solve the problem .

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

CPU The number of ( More accounting and more CPU,cat /proc/cpuinfo |grep -c processor) The more , The lower the system load , The more requests can be processed per second .

16、CPU load

cat /proc/loadavg

Check that the first three outputs exceed the system logic CPU Of 4 times .

17、CPU load

mpstat 1 1

Check %idle Is it too low ( For example, less than 5%).

18、 Memory space

free

Check free Is the value too low , It can also be used. # cat /proc/meminfo

19、SWAP Space

free

Check swap used Is the value too high , If swap used It's too high , Further inspection swap Do you move frequently :

vmstat 1 5

Observe si and so Is the value larger

20、 disk space

df -h

Check for partition usage (Use%) Too high ( For example, over 90%) Close to, as of, a partition , You can enter the mount point of the partition , Use the following command to find the most occupied file or directory :

du -cks * | sort -rn | head -n 10

21、 disk I/O load

iostat -x 1 2

Check I/O Usage rate (%util) Is it more than 100%

22、 Network load

sar -n DEV

Check network traffic (rxbyt/s, txbyt/s) Is it too high

23、 Network error

netstat -i

Check for network errors (drop fifo colls carrier), You can also use commands :# cat /proc/net/dev

24、 Number of network connections

netstat -an | grep -E “^(tcp)” | cut -c 68- | sort | uniq -c | sort -n

25、 Total processes

ps aux | wc -l

Check whether the number of processes is normal ( For example, over 250)

26、 Number of runnable processes

vmwtat 1 5

Column gives the number of runnable processes , Check if it exceeds the system logic CPU Of 4 times

27、 process

top -id 1

Observe if there are abnormal processes .

28、 Network state , Check DNS, Whether the gateway can be connected normally

ping traceroute nslookup dig

29、 user

who | wc -l

Check if there are too many login users ( For example, over 50 individual ) You can also use commands :# uptime.

30、 system log

# cat /var/log/rflogview/*errors Check if there are abnormal error records You can also search for some unusual keywords , for example :grep -i error /var/log/messagesgrep -i fail /var/log/messages

31、 Core log

dmesg

Check if there are abnormal error records .

32、 system time

date

Check that the system time is correct .

33、 Number of open files

lsof | wc -l

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

34、 journal

# logwatch –print To configure /etc/log.d/logwatch.conf, take Mailto Set it to your own email Address , start-up mail service (sendmail perhaps postfix), So that you can receive daily log reports . default logwatch Only yesterday's log , It can be used # logwatch –print –range all Get all the log analysis results . It can be used # logwatch –print –detail high Get more specific log analysis results ( Not just error logs ).

35、 kill 80 Port related process

lsof -i :80|grep -v “ID”|awk ‘{print “kill -9”,$2}’|sh

36、 Clear the dead process

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

37、tcpdump Grab the bag , To prevent 80 When the port is attacked, the data can be analyzed

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

38、 Then check that the IP And sort them from small to large Be careful “-t +0” There are two spaces in the middle

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

39、 See how many active php-cgi process

netstat -anp | grep php-cgi | grep ^tcp | wc -l

40、 View the system's self starting Services

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

41、kudzu Check the network card model

kudzu --probe --class=network

Common regular expressions

1. Regular expressions matching Chinese characters :[\u4e00-\u9fa5]

Commentary : It's a headache to match Chinese , With this expression, it's easy

2. Match double byte characters ( Including Chinese characters ):[^\x00-\xff]

Commentary : Can be used to calculate the length of a string ( A double byte character length meter 2,ASCII Character meter 1)

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

Commentary : Can be used to delete blank lines

4. matching HTML Tagged regular expression :<(\S*?)[^>]*>.*?|<.*? />

Commentary : The version circulating on the Internet is too bad , The above one can only match the part , There's nothing we can do about complex nested tags

5. A regular expression that matches the first and last whitespace characters :^\s*|\s*$

Commentary : Can be used to delete blank characters at the beginning and end of a line ( Including Spaces 、 tabs 、 Page breaks and so on ), Very useful expressions

6. matching Email Regular expression of address :

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Commentary : Form validation is very practical

7. Match URL URL Regular expression of :[a-zA-z]+://[^\s]*

Commentary : The function of the version circulated on the Internet is very limited , The above can basically meet the needs

8. Whether matching account number is legal ( Beginning of letter , allow 5-16 byte , Allow alphanumeric underscores ):^[a-zA-Z][a-zA-Z0-9_]{4,15}$

Commentary : Form validation is very practical

9. Match domestic phone number :\d{3}-\d{8}|\d{4}-\d{7}

Commentary : The matching form is as follows 0511-4405222 or 021-87888822

10. Matching Tencent QQ Number :[1-9][0-9]{4,}

Commentary : tencent QQ Number from 10000 Start

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

Commentary : China Post code is 6 Digit number

12. matching ×××:\d{15}|\d{18}

Commentary : China's ××× by 15 Bit or 18 position

13. matching ip Address :\d+\.\d+\.\d+\.\d+

Commentary : extract IP Useful for addresses

14. Match specific numbers :

^[1-9]\d*$ // Matching positive integer ^-[1-9]\d*$ // Matching negative integer ^-?[1-9]\d*$ // Matching integer ^[1-9]\d*|0$ // Match non negative integers ( Positive integer + 0)^-[1-9]\d*|0$ // Match non positive integers ( Negtive integer + 0)^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ // Match positive floating point ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ // Match negative float ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ // Match floating point ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ // Match non negative floating-point numbers ( Positive floating point + 0)^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ // Match non positive floating-point numbers ( Negative floating point number + 0)

Commentary : Useful when dealing with large amounts of data , Pay attention to correction in specific application

15. Match specific string :

^[A-Za-z]+$ // Match by 26 A string of English letters ^[A-Z]+$ // Match by 26 A string of uppercase letters ^[a-z]+$ // Match by 26 A string of lowercase letters ^[A-Za-z0-9]+$ // Match by numbers and 26 A string of English letters ^\w+$ // Match by number 、26 A string of English letters or underscores 

That's all Liangxu tutorial website For all of you Linux Related knowledge .

版权声明
本文为[Ma Nong Online]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121140442288X.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云