1. Find all files in the current directory that end with. Tar and move to the specified directory:
Find. -name "*.tar"-exec mv {}./backup/;
Note: Find–name is mainly used to find a file name,-exec, Xargs can be used to take the previous results, and then the action to be performed, generally with find in a lot of use, find use we can extend-mtime find the modified time,- Type is the specified object type (common include F for file, D for directory),-size specifies size, for example, frequently used: Find log files that are larger than 100M in the current directory 30 days ago and delete them.
Find. -name "*.log" –mtime +30–type f–size +100m |xargs rm–rf {};
2. Bulk unzip all files in the current directory ending in. zip to the specified directory:
For I in ' find. –name "*.zip" –type F '
Do
Unzip–d $i/data/www/img/
Done
Note: For i in (command);d o ... done is a common format for the for loop, where I is a variable and can be specified by itself.
3, 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
Add a a character at 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
Add a C character after a specific line: sed '/wuguangke/ac ' test.txt
Add a C character before the row: sed '/wuguangke/ic ' test.txt
For more SED commands please refer to the relevant documentation.
4, how to determine whether a directory exists, does not exist the new, the existence of printing information.
If
[!–d/data/backup/];then
mkdir–p/data/backup/
Else
echo "The Directory already exists,please exit"
Fi
Note: If ...; Then ... else. Fi: For the IF condition statement, the exclamation mark indicates that the "non-existent",-D represents the directory.
5, monitoring 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 root partition size
Df-h |sed-n '//$/p ' |awk ' {print $} ' |awk–f '% ' ' {print '} '
Note: awk ' {print $} ' means to print the 5th field, the meaning of-f is delimited, for example, in%, the simple meaning is to remove the percent sign, awk–f. ' {print '} ' separator.
(2), if condition to determine whether the size is greater than 90, if more than 90 send mail alarm
While sleep 5m
Do
For i in ' df-h |sed-n '//$/p ' |awk ' {print $ ' |sed ' s/%//g '
Do
Echo $i
If [$i-ge];then
echo "More than 90% Linux for disk space, please linux SA Check linux disk!" |mail-s "Warn linux/parts is $i%"
[Email protected]
Fi
Done
Done
Annotations: Using while ...; Do ...; Done is a while loop, and for, while, until, if, and conditional statements can refer to the following articles: http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html
6, 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-20
Annotations: Sort sorting, uniq (checking and deleting duplicates in a text file)
7. Sed another usage finds the current line, and then modifies the parameter following the line:
Sed-i '/selinux/s/enforcing/disabled/'/etc/selinux/config
The sed colon way sed-i ' s:/tmp:/tmp/abc/:g ' test.txt means to change/tmp to/tmp/abc/.
11. Print out the maximum and minimum values in 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 real print maximum minimum value: sed ' s///g ' a.txt |sort-nr|sed-n ' 1p; $p '
12, use SNMPD to crawl version of V2 cacti data mode:
Snmpwalk-v2c-c Public 192.168.0.241
13. Modify the text to replace the JK end with the YZ:
Sed-e ' s/jk$/yz/g ' b.txt
14. NET Grab Bag: tcpdump
TCPDUMP-NN host 192.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!
TCP/IP 7 layer Protocol physical layer – Data Link layer-network layer-Transport Layer-session Layer-presentation layer-application layer.
15, H3C Configure the community name configuration: First set the SNMP version as follows:
Snmp-agent sys-info Version v1 v2c, then set the community name: snmp-agent Community Read Public
16, show the most commonly used 20 commands:
Cat. Bash_history |grep-v ^# |awk ' {print $} ' |sort |uniq-c |sort-nr |head-20
Cite the linuxtone.org Community Classic Shell
Rookie Practice:
17, 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 {};
18. Write a script to move files larger than 100k in a directory to/TMP.
Find. -size +100k-exec MV {}/tmp;
19, write a firewall configuration script, only allow the remote host to access the local port 80.
Iptables-f
Iptables-x
Iptables-a input-p TCP--dport 80-j Accept
Iptables-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 to the Nginx log statistics, get the top 10 IP access (nginx log path:/home/logs/nginx/default/access.log).
Cd/home/logs.nginx/default
Sort-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) Maximum number of requests for maxkeepaliverequests 100 connections
(2) Options followsymlinks allow 192.168.1.1 to list
Order Deny Allow
Deny from all
Allow from 192.168.1.1
22. Replace the directory in the file
Sed ' s:/user/local:/tmp:g ' test.txt
Or
Sed-i ' s//usr/local//tmp/g ' test.txt
Linux Basic Operations Command 2