37 powerful Linux shell commands

  sonic0002        2013-09-16 07:47:16       40,450        0    

To work on Linux platform, you cannot avoid using shell commands to complete some tasks. These tasks can be as simple as list files in some directories or find some text in some file, or can be as complex as monitoring processes. In this post, we will share 37 powerful Linux shell commands.

  Task Commands
1 Delete file with 0 byte(empty file) find . -type f -size 0 -exec rm -rf {} \;
find . type f -size 0 -delete
2 Check process memory consumption ps -e -o "%C : %p : %z : %a"|sort -k5 -nr
3 Check process CPU utilizetion ps -e -o "%C : %p : %z : %a"|sort -nr
4 Print URLs in cache grep -r -a jpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}'
5 Check concurrent http connections and TCP connectio status netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
6 Replace no with yes in a line which contains Root in a file sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config 
7 Kill mysql process ps aux |grep mysql |grep -v grep  |awk '{print $2}' |xargs kill -9
killall -TERM mysqld
kill -9 `cat /usr/local/apache2/logs/httpd.pid` 
8 List service in rc.d ls /etc/rc3.d/S* |cut -c 15- 
9 Display multiline information with EOF cat << EOF
+--------------------------------------------------------------+
|   === Welcome to Tunoff services ===                         |
+--------------------------------------------------------------+
EOF
10 Use of for loop cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done
11 Get IP address ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-
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 Check connections to port 80 netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort
14 Check concurrent connections and TCP connection status to Apache netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
15 Check all jpg file size find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'
16 CPU number cat /proc/cpuinfo |grep -c processor
17 CPU load cat /proc/loadavg
18 CPU load mpstat 1 1
19 Memory space free
20 Disk usage df -h
21 Find files and directories taking most space in a disk space du -cks * | sort -rn | head -n 10
22 Disk I/O load iostat -x 1 2
23 Network load sar -n DEV
24 Network error netstat -i
cat /proc/net/dev
25 Network connection number netstat -an | grep -E “^(tcp)” | cut -c 68- | sort | uniq -c | sort -n
26 Total process number ps aux | wc -l
27 Check process tree ps aufx
28 Number of runnable processes vmwtat 1 5
29 Check whether a DNS server works properly dig www.baidu.com @61.139.2.69
30 Check number of users logged in currently who | wc -l
31 Check and search log cat /var/log/rflogview/*errors
grep -i error /var/log/messages
grep -i fail /var/log/messages
tail -f -n 2000 /var/log/messages
32 Kernel log dmesg
33 Time date
34 Opened handles lsof | wc -l
35 Capture network package tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts
36 Check repetitions of IP and print it with lowest to largest order less pkts | awk {'printf $3"\n"'} | cut -d. -f 1-4 | sort | uniq -c | awk {'printf $1" "$2"\n"'} | sort -n -t\  +0
37 kudzu to check network adaptor type kudzu --probe --class=network

Source : http://shentar.me/%E7%B2%BE%E9%80%8937%E6%9D%A1%E5%BC%BA%E5%A4%A7%E7%9A%84%E5%B8%B8%E7%94%A8linux-shell%E5%91%BD%E4%BB%A4%E7%BB%84%E5%90%88/

LIST  LINUX COMMAND 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

How functional testing works