One sentence for common linux O & M commands

Source: Internet
Author: User

Collect Common commands for Linux O & M management and system management. You can only record them for future viewing. You can also share with us. If you have a good command, paste it. This article is being updated.

1. linux Startup Process

Turn on the power --> BIOS boot self-check --> boot program lilo or grub --> kernel boot --> execute init (rc. sysinit, rc) --> mingetty (create a terminal) --> Shell

2. Bind a NIC to multiple IP addresses

# ifconfig eth0:1 192.168.1.99 netmask 255.255.255.0

3. Set DNS and gateway

# echo "nameserver 202.16.53.68" >> /etc/resolv.conf# route add default gw 192.168.1.1

4. pop up and remove the optical drive

# eject# eject -t

5. Use date to query the date of yesterday

# date --date=yesterday

6. query the row number of the empty row in file1.

# grep ^$ file

7. query the rows ending with abc in file1.

# grep abc$ file1

8. Print the file1 file 1st to the third line.

# sed -n '1,3p' file1# head -3 file1

9. Clear files

# true > 1.txt# echo "" > 1.txt# > 1.txt# cat /dev/null > 1.txt

10. Delete all empty directories

# find /data -type d -empty -exec rm -rf {} ;

11. How to batch Delete Empty files (files with size equal to 0) in linux

# find /data -type f -size 0c -exec rm -rf {} ;# find /data -type f -size 0c|xargs rm –f

12. delete files five days ago

# find /data -mtime +5 -type f -exec rm -rf {} ;

13. Delete the duplicate parts of the two files and print other

# cat 1.txt 3.txt |sort |uniq

14. Attackers can exploit the remote server host name.

# echo `ssh $IP cat /etc/sysconfig/network|awk -F = '/HOSTNAME/ {print $2}'`

15. Monitor network card Traffic in real time (install iftop)

# /usr/local/iftop/sbin/iftop -i eth1 -n

16. view the system version

# lsb_release -a

17. Force the user to log out

# pkill -KILL -t pts/1

18. tar backup and Restoration

# tar -g king -zcvf kerry_full.tar.gz kerry# tar -g king -zcvf kerry_diff_1.tar.gz kerry# tar -g king -zcvf kerry_diff_2.tar.gz kerry# tar -zxvf kerry_full.tar.gz# tar -zxvf kerry_diff_1.tar.gz# tar -zxvf kerry_diff_2.tar.gz

19. forward requests from local port 80 to port 8080. The current host's Internet IP address is 202.96.85.46

-A PREROUTING -d 202.96.85.46 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.9.10:8080

20. Execute/usr/bin/httpd. sh once every two hours from to every month.

# crontab -e0 6-12/2 * 11 * /usr/bin/httpd.sh

21. view the processes that occupy port 8080

# netstat -tnlp | grep 8080lsof -i:8080

22. In the Shell environment, how does one view how long the remote Linux system has been running?

# Ssh user @ ip address of the monitored host "uptime"

23. Command for viewing CPU usage

Refresh Every 5 seconds, data with CPU usage on the rightmost side # vmstat 5 top, then sort by Shift + P, by process processor usage # top

24. Command for checking memory usage

Use the free command to view memory usage # free-mtop, Shift + M, and sort by process memory usage # top

25. view disk I/o

Use iostat to view disk I/o of Disk/dev/sdc3, and refresh every two seconds # iostat-d-x/dev/sdc3 2

26. File System Repair

# Fsck-yt ext3/-t specifies the file system-y automatically answers yes to the found question

27. The read command automatically exits after 5 seconds

# read -t 5 

28. What does grep-E-P mean?

-E, -- extended-regexp adopts an extended regular expression. -P, -- perl-regexp adopts regular perl expressions

29. vi Editor (for modification, add, search)

Insert mode

I insert a cursor before the cursor I insert A cursor at the beginning of the cursor line insert a cursor at the end of the line insert o cursor at the bottom of the line insert A row, insert a row at the beginning of the line insert O cursor at the row insert A line, insert G at the beginning of the line to move nG at the beginning of the last line to n + at the beginning of the n line to move n rows, n at the beginning of the line to move n rows up, and the beginning of the line: /str/move from current to right to where str exists :? Str? From the current left to the place where str exists: s/str1/str2/Replace the first str1 with str2: s/str2/str2/g replace all str1 found in the current row with str2: n1, n2s/str1/str2/g replace all str1 found from line n1 to line n2 with str2: 1 ,. s/str1/str2/g replace all str1 from row 1st to the current row with str2 :., $ s/str1/str2/g replace all str1 from the current row to the last row with str2

30. Copy files between linux servers

Copy local file 1. sh to remote 192.168.9.10 server/data/directory # scp/etc/1.sh king@192.168.9.10:/data/copy remote 192.168.9.10 server/data/2. sh file to local/data/directory # scp king@192.168.9.10:/data/2.sh/data/

31 bytes uses the sedcommand to replace the TEST of line 1 of the test.txt file with the TSET.

# sed -i '23s/TEST/TSET/' test.txt# sed -i '23 s/TEST/TSET/' test.txt

32. Enable the history command to display the time

# export HISTTIMEFORMAT="%F %T "

33. How to view the ports opened by the target host 192.168.0.1

# nmap -PS 192.168.0.1

34. How to view Network Connections

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

35. How to view the library files used by the current system

# ldconfig -v

36. How to view the driver version of the NIC

# ethtool -i eth0

37. Use tcpdump to monitor tcp port 80 of host 192.168.0.1

# tcpdump tcp port 80 host 192.168.0.1

38. view other users' email lists

# mial -u king

39. Cutting large files

Split by 1000 lines of each file # split-l 1000 httperr8007.log httperr split by 5 MB per file # split-B 5 m httperr8007.log httperr

40. Merge files

Extract the union of the two files (only one copy of the duplicate rows is retained) # cat file1 file2 | sort | uniq extracts the intersection of the two files (only the files that exist in the two files at the same time are left) # cat file1 file2 | sort | uniq-d Delete the intersection and leave other rows # cat file1 file2 | sort | uniq-u

41. Services Running in print text mode

# chkconfig --list|awk '$5~/on/{print $1,$5}'

42. Delete 0-byte files

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

43. View processes and arrange them by memory size

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

44. 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]}'

45. Obtain an IP address

# Ifconfig eth0 | sed-n '2p' | awk '{print $2}' | cut-c 6-30perl to obtain the IP Address: # ifconfig-a | perl-ne 'if (m/^ s * inet (? : Addr :)? ([D.] + ).*? Cast/) {print qq ($ 1n); exit 0 ;}'

46. Obtain the memory size

# free -m |grep "Mem" | awk '{print $2}'

47. view the number of CPU Cores

# cat /proc/cpuinfo |grep -c processor

48. view disk usage

# df -h

49. Check the number of active PHP-cgi Processes

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

50. view the hardware manufacturer

# dmidecode -s system-product-name


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.