Common Linux Command Memos

Source: Internet
Author: User
Tags base64 log log syslog system log root access rsync

1. Delete the 0-byte file:

Find-type f-size 0-exec rm-rf {} \; In Exec, {} represents the file to find, \;

2. View the process

Sort by memory from large to small: ps-e-o "%c:%p:%z:%a" |sort-k5-nr

Rank by CPU utilization from large to small: ps-e-o "%c:%p:%z:%a" |sort-nr

3. Check if the SCSI drive cache is open:

Sdparm-g WCE/DEV/SDA |grep WCE |awk ' {print $} '

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

5. View the number of TCP connections:

Netstat-na | grep "$IP: 80" | Wc-l

6. See which processes are currently running:

Ps-a

7. Display the services that are running Level 3 open:

ls/etc/rc3.d/s* |cut-c 15-

8. View the number of CPUs:

Cat/proc/cpuinfo |grep-c Processor

9. View CPU Load:

Cat/proc/loadavg

10. View CPU Information:

Mpstat 1 1//Check if the%idle is too low

11. View memory Space:

Free//Check if the value is too low, or use Cat/proc/meminfo

12. View Swap space:

Free//Check whether the swap used value is too high if the swap used value is too high, further check if the swap action is frequent

Vmstat 1 5//See if Si and so values are large

13. View disk space:

Df-h//Check if partition usage (use%) is too high (for example, more than 90%) If a partition space is found to be nearly exhausted

Du-cks * | Sort-rn | Head-n 10//Enter the mount point of the partition to find the file or directory that occupies the most space

14. View the disk I/O load:

Iostat-x 1 2//check if I/O usage (%util) exceeds 100%

15. View Network Load:

Sar-n DEV//Check network traffic (rxbyt/s, txbyt/s) is too high

16. Network error:

Netstat-i//Check if there is a network error (drop FIFO Colls carrier) also available command: Cat/proc/net/dev

17. Number of network connections:

Netstat-an | Grep-e "^ (TCP)" | Cut-c 68-| Sort | uniq-c | Sort-n

18. View the total number of processes:

PS aux | Wc-l//Check whether the number of processes is normal

19. Output the status value of the server at a given time interval:

Vmstat 3 5///First parameter: sampling interval in seconds; second parameter: Number of samples

20. Real-time Process view:

Top-id 1//Observe if an abnormal process occurs

21. Network status, DNS, gateway information:

NETSTAT-A//View network status

Route-n//View gateway Information

Cat/etc/resolvconf/resolv.conf.d/original//dns (Ubuntu)

22. Number of users logged in:

W.H.O. | Wc-l//View the number of logged-on users, or use the command: uptime

23. System log:

Grep-i Error/var/log/syslog//Check for abnormal error records by searching for exception keywords
Grep-i Fail/var/log/syslog
Egrep-i ' Error|warn '/var/log/syslog

24. System Boot Information log:

DMESG | TAIL-F//Check abnormal error Record of last boot

25. Number of open files:

lsof | Wc-l//Check the total number of open files

26. View the 80 port process:

Lsof-i: 80|grep-v "ID"

27. Find Zombie Processes:

Ps-eal | awk ' {if ($ = = "Z") {print $4}} '

28. See how many php-cgi processes are active:

NETSTAT-ANP | grep php-cgi | grep ^tcp | Wc-l

29. Create more than one directory at a time:

Mkdir-p/home/ggf/shell {TEST1,TEST2,TEST3}

30. Quickly back up a file:

CP FILE_NAME{,.BKP}//Rename a file: MV A.txt b.txt

31. Create an empty file or empty an existing file:

> Test.txt

32. Show the remaining memory:

free-m | grep Cache | awk '/[0-9]/{print $4 ' MB '} '

33. Get the contents of the 第50-60 line in the Test.txt file:

< Test.txt sed-n ' 50,60p '

34. Search for files created or modified within 30 days:

Find/usr/bin-type f-mtime-30

Find/usr/bin-type f-amin-30//search for files accessed within 30 minutes

35. Search for lines ending in a-Z, end of line search $:

Grep-n ' [a-z]$ ' 123.txt

36. View the number of files in the current directory:

Ls-al |grep "^-" |wc-l

37. Display the latest contents of the log (constantly refresh to show the latest log):

Tail-n 10-f/var/log/syslog.log

38. Clear the contents of the file:

Cat/dev/null >/home/users/example/aa.log

39. Use Base64 encoded Input.txt file and output to input.b64:

OpenSSL base64-e-in input.txt-out input.b64

40. Encode/decode the string using base64:

Code: Echo-n ' 12345SSDLH ' | OpenSSL base64-e

Decode: Echo ' mtizndvzc2rsaa== ' | OpenSSL base64-d

41. Show all 22-port (SSH) connections:

Netstat-nt |grep:22 |awk ' {print $} ' |sort |uniq-c

42. Delete all files with a. tmp suffix in the current directory:

Find.-type f-name "*.tmp"-delete

MD5 and SHA Checksum:

md5sum filename

Shasum filename

44. A set of commands for querying hardware information:

LSCPU: For querying CPU information

LSHW: Display hardware information table (requires root permission, preferably output to file instead of terminal)

HWInfo: Displays hardware information (debug info, preferably output to a file. Otherwise it will be as sad as the tree command is executed in the/directory and output to the terminal)

LSPCI:PCI Bus and equipment information

LSBLK: Listing block device information

LSUSB: List USB bus information

LSSCSI: List SCSI Device information

45. Obtain the MD5 fingerprint of the file in the current directory:

Find. -type f-exec md5sum {} \; > SUM.MD5

46. View the details of the port-process:

Lsof-pan-i tcp-i UDP

47. Guessing the operating system used by the target host (using the Network Scan Tool Nmap):

Nmap-o--osscan-guess www.ifeng.com//requires root access


48. Scan the host network port:

NMAP-SS 61.18.85.17//requires root permission to scan host TCP port open condition

NMAP-SU 61.18.85.17//requires root permission to scan host UDP port open condition

Nmap-stu localhost//check for native (localhost) open ports

49. Whether the host in the probing domain is online:

NMAP-SP 192.168.1.0/24//using the ping command to print out the host that responds to the scan

NMAP-SL 192.168.1.0/24//lists each host on the specified domain and does not send any messages to the target host

Ubuntu12.04 System service Management:

Initctl List | grep start//To view the system's current running status as Start service

51. Smash a file named Test.txt:

Shred–u test.txt//overwrite file with random character code, the function of this command is suitable for the effect of file shredding.

This command is included in the GNU Core Utilities software package. Truncation and deletion of files after-u,--remove overwrite parameters

52. Security Removal Tool Wipe:

Delete file: Wipe file.txt
Delete directory: Wipe-r/home/user/test/
Delete Partition: WIPE/DEV/SDB1

53. Quickly delete massive files-using rsync:

rsync--delete-before-a-h-v--progress--stats/tmp/test/log///fast deletion of a massive log method (the replacement principle of rsync, fast removal)

                                                                                                                      //-delete-before  the recipient to delete before transmission

                                                                                                                      //-a  archive mode, which means to transfer files recursively and keep all file attributes

                                                                                                                      //-h  Keep hard-connected files

                                                                                                                      //-v  verbose output mode

                                                                                                                      //-progress  Display the transfer process during transmission

-stats gives the transfer status of some files

54. A set of commands about a package:

Dpkg-l apt//View list of installed files

Dpkg-s/usr/bin/apt-get//Find out which package Apt-get belongs to

Dpkg-reconfigure apt//reconfigure apt pack

Apt-cache depends apt//Find a dependency package for apt packages

Apt-cache rdepends apt//find packages that depend on apt packages

55. Use a maximum of 10 commands:

History | Sed-e ' S/^sudo//' | awk ' {print $} ' | Sort | uniq -C | Sort -rn | Head//Run command will be saved by Ubuntu to ~.bash_history

The Uniq command can detect or delete adjacent duplicate rows in a file, usually with sort

56. A set of file-related commands:

Cutting and merging:

Split-b 1mb-d MySQL.log mysql-log_//partition Mysql.log files in 1MB, save as mysql-log_xx as file name The file Set

Split-l Syslog.log Syslog_//with 1000 behavior one unit split syslog.log log file, saved as Syslog_x X-Series File Set

Cat mysql-log_00 mysql-log_01 mysql-log_02 > Mysql-log//merge split files

Replacement characters:

Cat File | TR p p//single-character replacement

Cat File | tr [A-z] [a-z]//lowercase letter to uppercase

Extract text:

Cut-d '-f1,3 file//Extract text from First and third fields
Cut-d '-f1-3 file//Extract text from second to fourth fields

Text sort:

Sort-n file.txt//Sort by number

Find dad for orphan files:

Find.     -type f-nouser-exec chown username {} \; In the current directory, change the user of the non-master file to username

To find special files:

Find. -type D-perm-1000-print//Find a valid T-bit file in the current directory

Find. -type F-perm-4000-print//Find a valid file in the current directory to find suid bits

Find. -type f-perm-2000-print//Find sgid-bit valid files in the current directory

Find/dev-nogroup-nouser-print//Find no Master File

57.

58.

59.

60.

Note:

Important principles:

Type less, accomplish more (do not play more)

DRY, don ' t repeat yourself (don't repeat yourself)

Care about your tool (caring for your tools)

Report:

Learning commands should be logged in every day website:http://commandlinefu.cn/

Common Linux Command Memos

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.