Linux operations common commands and knowledge

Source: Internet
Author: User
Tags clear screen

1. Find all files in the current directory that end with. Tar and move to the specified directory:

Find. -name "*.tar"-exec mv {}./backup/; Find the log file that is larger than 100M in the current directory 30 days ago and delete it. Find  . -name "*.log" –mtime +30–type f–size +100m |xargs rm–rf {}; Write a script to find the last created time is 3 days ago, the suffix is *.log file and deleted. Find. -mtime +3  -name "*.log" |xargs rm-rf {}; Write a script to move files larger than 100k in a directory to/TMP. Find. -size +100k-exec MV {}/tmp; 2, bulk unzip all files ending in. zip in the current directory to the specified directory: For i  in   ' find. –name "*.zip" –type F ' dounzip–d $i/data/www/img/done3, sed common Life collection: test.txt do test   How to get rid of the beginning of the line. Character: Sed-i ' s/^.//g ' test.txt in Add a a character to the beginning of the line: sed ' s/^/a/g '    test.txt add a a character at the end of the line: sed ' s/$/a/'      Tets.txt adds a C character after a specific line: sed '/wuguangke/ac ' test.txt adds a C character before the row: sed '/wuguangke/ic ' test.txt4, how to tell if a directory exists, not exist, exists to print the information. if[!–d/data/backup/];thenmkdir–p/data/backup/elseecho   "The Directory already exists,please exit" fi annotations: If ...; Then ... else. Fi: For the IF condition statement, the exclamation mark indicates that the "non-existent",-D represents the directory.  5, monitor the Linux disk root partition, if the root partition space is greater than or equal to 90%, send mail to the Linux SA (1), print the root partition size df-h |sed-n '//$/p ' |awk ' {print $ '} ' |awk–f '% ' ' {print '} ' (2), if condition determines whether the size is greater than90, if greater than 90 sends the message alarm while sleep 5mdofor i in ' df-h |sed-n '//$/p ' |awk ' {print $ |sed ', ' the "s/%//g ', '" Doecho $iif [$i-ge 90]; Thenecho "More than 90% Linux for disk space, please linux SA Check linux disk!" |mail-s "Warn linux/parts is $i%" &nbsp ; [Email protected]fidonedone6, Statistics nginx Access log, the number of traffic ranked in the top 20 IP address: Cat access.log |awk ' {print $} ' |sort|uniq-c |sort-nr | head-207, sed another usage finds the current line, and then modifies the parameter following the line: Sed-i '/selinux/s/enforcing/disabled/'/etc/selinux/configsed colon sed-i ' s:/ Tmp:/tmp/abc/:g ' test.txt means to change/tmp to/tmp/abc/. 11. Print out the maximum and minimum value of a file: Cat a.txt |sort-nr|awk ' {}end{print} nr==1′cat a.txt |sort-nr |awk ' End{print} nr==1′ This is the true print maximum minimum value: Sed ' s///g ' a.txt |sort-nr|sed-n ' 1p; $p ' 13, modified text to be replaced with JK end in Yz:sed-e ' s/jk$/yz/g ' b.txt14, net grab: Tcpdumptcpdump-nn Host 1 92.168.56.7 and port 80 fetch 56.7 packets through 80 requests. TCPDUMP-NN host 192.168.56.7 or! Host 192.168.0.22 and port 80 excludes 0.22 80 ports! 16, show the most commonly used 20 commands: Cat. Bash_history |grep-v ^# |awk ' {print $} ' |sort |uniq-c |sort-nr |head-2019, write a firewall configuration script that only allows farHost to access the local 80 port. Iptables-fiptables-xiptables-a input-p TCP--dport 80-j acceptiptables-a input-p tcp-j reject or iptables-a INPUT- M state--state new-m tcp-p TCP--dport 80-j accept 20, write a script for nginx log statistics, get the top 10 IP access (nginx log path:/home/logs/nginx/ Default/access.log). Cd/home/logs.nginx/defaultsort-m-K 4-o access.logok access.1 access.2 access.3 ..... cat Access.logok |awk ' {print $} ' |sort-n|uniq-c|sort-nr |head-10 21. Write down the meanings of the following commands (1) maxkeepaliverequests    100   Maximum number of requests to connect (2) Options followsymlinks   allow 192.168.1.1 to list                 order Deny allow                deny from All        allow 192.168.1.122. Directories in the replacement file sed ' s:/user/local:/tmp:g ' test.txt or sed-i ' s//usr/local//tmp/g ' test.txt     

# CTRL + L-Clear screen

# CTRL + C-Abort command

# Ctrl + D-exits the shell as if it could also represent EOF

# CTRL + Z-the current process is placed in the background and FG is restored.

# Ctrl + R-Find from command history

# CTRL + A-cursor moves to the beginning of the line

# CTRL + E-the cursor moves to the end of the line

# Ctrl + U-clear the cursor to the beginning of the character

# Ctrl + W-clear the cursor before a word

# Ctrl + K-clears the character of the cursor to the end of the line

# CTRL + T-swap the first two characters of the cursor

# Ctrl + Y-paste the characters that were removed from the previous Ctrl+u class command

# CTRL + P-Previous command

# CTRL + N-Next command

# Ctrl + V-Input control word such as CTRL + V. <ENTER>, input ^m

# CTRL + F-Move the cursor back one character

# CTRL + B-cursor moves forward one character

# Ctrl + H-delete a character before the cursor

# N+<ESC>+F-Move the cursor back n words, n is 1 can be omitted

# N+<ESC>+B-the cursor moves forward n words, n is 1 can be omitted

# CTRL + S-Suspend current shell

# CTRL + Q-Re-enable

<esc>+d is removed from the beginning of the cursor to the end of the line. The Suspended shell

# !! -Previous command

#!-n-Countdown nth History command

#!-n:p-Print previous command (not executed)

# !? String -The latest command with "string" #!-n:gs/str1/str2/-Replaces the str1 of the last nth command with STR2 and executes (replaces the first only if no G is added)

Linux operations common commands and knowledge

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.