1. Find the same number in two files
Diff-y Xx.txt Oo.txt | Egrep-v "<|>" | awk ' {print $} '
2. Print the first few lines to the first line
Cat 1 | awk ' Nr==2,nr==4{print} '
1. Remove the Linux remote user connection session
[Email protected] logs]# W 10:45:28 up Days, 16:23, 4 users, load average:0.00, 0.00, 0.00USER TTY FR OM [email protected] IDLE jcpu PCPU whatroot tty1 - Sun21 4days 0.00s 0.00s-bashroot pts/0 192.168.1.2 09:11 0.00s 0.07s 0.00s wroot PTS/2 192.168.1.2 09:45 30:53 0.07s 0.07s-bashroot pts/3 192.168.1.8 10:20 22:05 0.02s 0.00s vi operation.log[[email protected] logs]# skill-kill-v pts/3pts/3 root 21217 vi PTS/3 root 24331 bash
2. Remote execution of commands via SSH
[Email protected] bin]# iip= "192.168.1.10" [[email protected] bin]# ssh $IIP w 10:54:13 up Days, 20:17, 1 user,
load average:0.00, 0.00, 0.00USER TTY from [email protected] IDLE jcpu PCPU whatroot Tty1 - 21mar14 4days 0.09s 0.09s-bash
3. Remote batch execution of MySQL scripts via ssh
#iplist1 = (' Cat.. /tools/dblist | Grep-v \# | awk ' {print '} ' | Sed "1,1d") #userlist2 = (' Cat. /tools/dblist | Grep-v \# | awk ' {print $} ' | Sed "1,1d") #passwordlist3 = (' Cat. /tools/dblist | Grep-v \# | awk ' {print $} ' | Sed "1,1d" ') for ((i=0;i<=${#list1 [@]};i++));d o iip= ' echo ${list1[i]} | awk-f "." ' {print $4} ' ssh ${list1[i]} mkdir/home/sqlscrip/ ssh ${list1[i]} mkdir/home/sqlscrip/$IIP Clear SCP: /sqlscrip/$IIP/* ${list1[i]}:/home/sqlscrip/$IIP Clear #path list4= (' ls. /sqlscrip/$iip ') for ((w=0;w<=${#list4 [@]};w++)); Do if ["117" = = "$iip"] then ssh ${list1[i]} "Mysql-h ${list1[i]}-u ${list2[i]}-p${list3[i]} < /HOME/SQLSCRIP/${IIP}/${LIST4[W]}; " Clear fi do ssh ${list1[i]} ' Rm-rf/home/sqlscrip ' Done
4. Download the war package via SVN
#list第五行为list = (' Cat.. /tools/list | awk ' {print $} ' | sed "1,1d" ') for ((i=0;i<${#list [@]};i++));d O curl-u wangyong:abcd1234-o ${ List[i]} war= ' echo ${list[i]} | awk-f "/" ' {print $NF} ' mv $war: /workapp/done
5. Extract the war package to the specified directory
SSH ${ip} Unzip ${tomcat directory}/webapps/${war package name}.war-d ${tomcat directory}/webapps/${specified directory}
6, multi-linux server establish trust relationship
Ssh-keygen-t RSACD ~/.sshscp-r id_rsa.pub $ip:/root/.ssh/$ipssh $ip ' Touch ~/.ssh/authorized_keys && chmod 644 ~ /.ssh/authorized_keys ' ssh $ip "cat ~/.ssh/$ip >> ~/.ssh/authorized_keys"
7. Delete empty files in a directory
Find: /new/$serve/properties-type f-size 0-exec rm-f {} \;
8. Delete files less than 10b in a directory
#Delete the files smaller than 10B for i in ' ls-l. /new/$serve/properties/| Sed-e ' 1d ' | awk ' $ < {PRINT$NF} ' do rm-rf. /new/$serve/properties/$i done
9, Linux through alias set shortcut command
Command () {list1= (' cat ~/.BASHRC | grep custom ') for ((i=0;i<=${#list1 [@]};i++));d o if [["${list1[i]}" = "#custom" ] then echo "[warn] the command had already been Initialized,there ' s no need to repeat the Operati On, thank you! " Break else path= ' pwd ' #初始命令 #Initialization commands. echo "#custom" >> ~/.bashrc echo "Alias l= ' Ll-al '" >> ~/.bashrc echo "Alias con f= ' CD ' echo $path '/. /conf ' ">> ~/.bashrc echo" Alias bin= ' CD ' echo $path '/. /bin ' ">> ~/.bashrc echo" Alias new= ' CD ' echo $path '/. /new ' ">> ~/.bashrc echo" Alias too= ' CD ' echo $path '/. /tools ' >> ~/.bashrc Echo ' Alias hostlist= ' cat ' echo $path '/. /tools/.hostlist ' ">> ~/.bashrc echo" Alias un= ' CD ' echo $path '/. /' ">> ~/.bashrc echo" Alias bak= ' CD ' ECHo $path '/. /bak ' ">> ~/.bashrc echo" Alias app= ' CD ' echo $path '/. /workapp ' >> ~/.bashrc Echo ' Alias. = ' CD. /' ">> ~/.BASHRC source ~/.BASHRC Fidone}
10. Referencing other shell scripting methods
# # # ====================================================#### Auth:wonter # # # # # date:2014-06-12 # # Path: javame.cnblogs.com # # # # # # ====================================================###!/bin/sh# references tool.sh script methods ... /tools/tool.sh#parameterspar#capture ip#capture Pathconfig
11. Get the name of the script itself
#Automatically obtain Configuration Filesname= ' echo $ Uname= ' echo $name | Awk-f "/" ' {print $} ' | Awk-f "." ' {print $} ' #Uniform configurationserve= ' $uname '
12, check if there is a folder, no new folder
Bak_mk= ". /bak/$serve "new_mk=". /new/$serve "If [!-D $bak _MK]; Thenmkdir $bak _mkfiif [!-d $new _MK]; Thenmkdir $new _MKFI
Determine if the file is empty
If [-s $file]; Then
echo "Not Empty"
Fi
13. Statistical script Execution Time
st= ' date + '%y-%m-%d%h:%m:%s '
#执行方法 start en= ' date + '%y-%m-%d%h:%m:%s "' st_c= ' date-d " $st "+%s ' en_c= ' date-d " $en "+%s ' interval= ' expr $en _c-$st _c ' Echo ' start start-up time : ${st} ' echo ' Start end time : ${en} ' C15/>echo "Total consuming time : ${interval} Seconds"
14. Shell Definition Collection
#namelist1 = (' Cat.. /tools/list | Grep-v \# | awk ' {print '} ' | Sed "1,1d") #iplist2 = (' Cat. /tools/list | Grep-v \# | awk ' {print $} ' | Sed "1,1d") #servelist3 = (' Cat. /tools/list | Grep-v \# | awk ' {print $} ' | Sed "1,1d" ') for ((i=0;i<=${#list1 [@]};i++));d o cp. /conf/.model. /CONF/${LIST1[I]}.CONF CP. /bin/.model.wy. /bin/${list1[i]}.wy CP. /bin/.model.yw. /bin/${list1[i]}.ywdone
15. Record the script performer user and IP
#Perform Operationecho "operator:" read mea= ' TTY | Awk-f "/dev/" ' {print $} ' date ' +%y-%m-%d%h:%m:%s ' >>. /logs/operation.logecho ' W | grep $a | awk ' {print $} ' "${me} > Perform operation:one" >>. /logs/operation.log
16. Regular statements in the shell
For i in ' Cat. /conf/$confs | grep start | awk-f ">>" ' {print $} ' | awk-f "_" ' {print $} ' do if [["${i}" = = "Shiro"] then sed-n-E '/>>shiro/,/>>shiro/p ' $confs |grep-v ' >>shiro ' > $pro _shi cat $ Pro_shi | Col-b >. /temp/m1 Cat. /temp/m1 > $pro _shi elif [["${i}" = = "jdbc"] "then sed-n-E '/>>jdbc/,/>>jdbc/p ' $ Confs |grep-v ' >>jdbc ' > $pro _jdbc cat $pro _jdbc | col-b > ... /temp/m1 Cat. /temp/m1 > $pro _jdbc fi
Done
17, Shell write a timed process (not recommended I this writing, should have better!) )
# # # ====================================================#### Auth:wonter # # # # # # # # date:2014-06-12 timing.sh # # # # # # ====================================================###!/bin/shecho "Please enter the timing threshold (format: ' Date + '%Y-%m- %d%h:%m "')" read Timingecho "timed task set up, please rest assured ..." Ti () {while Truedo time= ' date + "%y-%m-%d%h:%m" ' if [["${ Time} "= =" ${timing} "]" then echo "timed task:" #定时清理日志 rm-rf. /logs/* #定时备份日志 #定时执行脚本 break fidone}ti&
18. Execute script by parameter mode tools.sh
#!/bin/shtrust () {#建立信任echo "Please enter the Trust machine IP: (hint: You need to enter the password three times!) ) "Read Iptrusts}command () {#初始化命令command}case" $* "in Trust) Trust ;; command) command ;; *) echo "----------------------------------------" echo "pls:http://javame.cnblogs.com Welcome" echo "----------------------------------------" echo " Host Trust | or | Initialize command (initial) " echo" tools.sh Trust | or | tools.sh command " echo"----------------------------------------" ;; Esac
19, the terminal sends back the session to the other user limited root user
echo "Enter what you want to say:"
Read Spkecho $SPK >/dev/stdin >/DEV/PTS/2
20, a directory of all Files Unified Batch modification IP
Sed-i " s/10.0.0.1/10.0.1.2/g" ' grep ' 10.0.0.1 '-rl/opt/uer/wy '
21. Number of links and number of processes
#链接数netstat-N | awk '/^tcp/{++y[$NF]} END {for (w in y) Print W, y[w]} ' #统计httpd协议连接数进程数ps-ef|grep httpd|wc-lps aux|grep httpd|wc-l# handle number L Sof-n|awk ' {print $} ' |sort|uniq-c|sort-nr|more #查看进程占用内存ps aux |awk ' ($ ~apache) && ($6>50) {print $} '
22. Three ways to view threads in Linux
1, top-h Manual said:-h:threads Toggle plus this option to start a top,top line to display a thread. Otherwise, it displays a process one line. 2, PS XH Manual said: H Show threads as if they were processes so that all existing threads can be viewed. 3, PS-MP <PID> Handbook said: M show threads after processes this allows you to see the number of threads that are in a process.
23. View the IP addresses that connect to a service port
Netstat-nat | grep "192.168.1.20:8443" |awk ' {print $} ' |awk-f: ' {print $4} ' |sort|uniq-c|sort-nr|head-20
24, common compression decompression name
25, thick accumulation of thin hair, continuous updating and accumulation, please pay attention to javame.cnblogs.com
1.gzexe-d decryption
2.Address 192.168.3.202 maps to Bogon, but this does is not a map back to the address-possible break-in attempt!
Workaround: Vim/etc/ssh/ssh_config Modify the Gssapiauthentication value to No
3. Print the specified line
Sed-n-i '/pid/,+600000000 P ' file
4.sed usage
Insert data in the first row sed-i 1 "i\\ $icare _ip" file only prints the third row sed-n ' 3p ' datafile only view the file line 100th to line No. 200 sed-n ' 100,200p ' files delete the second to fifth line sed ' 2,5d ' da Tafile Delete rows containing "2014-10-19" to rows that contain "2014-10-29" sed '/2014-10-19/,/2014-10-29/d ' datafile delete the content containing "My" to line tenth of the SED '/my/, 10d ' datafile
SED option-E for multiple edits
Sed-e ' 1,10d '-e ' s/my/your/g ' datafile
5. Interactive input
{echo "Who"} | SSH 192.168.48.73
Collections in 6.shell
List1= (' Cat.. /tools/list | Grep-v \# | awk ' {print '} ' | Sed "1,1d" ') for ((i=0;i<${#list1 [@]};i++));d Osh./${list1[i]}.wydone
7. Determine if there is
if [!-D $bak _MK]; Thenmkdir $bak _MKFI
8. For ^m
Dos2unix
9. Obtain the IP of the last login system
Last-n 5
10.AWK count the number of bytes in a file under a folder
Ls-l |awk ' BEGIN {size=0;} {size=size+$5;} End{print "[End]size is", size} ' [End]size is 8657198ls-l |awk ' BEGIN {size=0;} {size=size+$5;} End{print "[End]size is", size/1024/1024, "M"} ' [End]size is 8.25889 M
About Find search targeting:
11. File Name Search
12. Perform after lookup
Find./-name 192.168.48.154-exec cat > 1 {} \;
13. Delete empty files
Find./-type f-size 0-exec rm-rf {} \;
14. Find a file size of 0 or an empty directory
15. Check for files larger than 512k
16. Print multiple files to a file
Find./-name "[1-9].sh"-exec cat > 3 {} \;
17. Filter folders under Directory
18. Batch Modification
Find./-name "[1-9].sh"-exec sed-i s/0/9/g {} \;
19.-o equals and
Find./-name "1.sh"-o-name "2.sh"
20. Change in two days
21. Change within two minutes
Find/home-mmin-2
Files accessed within 22.10 minutes
Find/home-amin-10
Files accessed within 23.2 hours
Find/home-atime-2
24. Copy what you find out to another place
Find *.c-exec cp ' {} '/tmp '; '
25. Check that the/root directory is mounted on that disk partition
Df-h/root
26. Soft connection, Hard link
Ln-s/home/root/homeln-b/home/run.sh/root/run.sh
27. Unzip to the specified directory
Tar zxvf/filename.tar.zip-c/Home
28.VI Instruments
GG First line G last line d1g delete cursor line to first line DG DELETE cursor line to last line YY copy cursor line A at the last character of the cursor at the beginning of the Insert ZZ Save exit
29.^m garbled
Yum Install Dos2unix
30. Modify post-Linux login information
Vi/etc/motd
31. Timed Task Script
cmd= "cd/root/polling/bin/&&/root/polling/bin/run.sh" echo-n "*" >>/var/spool/cron/rootecho-n "6" > >/var/spool/cron/rootecho-n "*" >>/var/spool/cron/rootecho-n "*" >>/var/spool/cron/rootecho-n "*" >>/var/spool/cron/rootecho $cmd >>/var/spool/cron/root
32. Group Network Trust
{ECHO-E "\ n"} | Ssh-keygen-t rsa-p "Cp-r ~/.ssh/id_rsa.pub ~/.ssh/authorized_keyscd ~/.sshscp-r id_rsa.pub $ip:/root/.ssh/$ipssh $ip ' Touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys ' ssh $ip ' cat ~/.ssh/$ip >> ~/.ssh/ Authorized_keys "
33. About Shell Entry handling
$ A script name $ "Location parameter #1 $-$9 positional parameter #2-#9 ${10} position parameter #10 the number of $# positional parameters" $* "all positional parameters (as a single string) *" [email protected] "All positional parameters (each As a standalone string) ${#*} The number of command-line arguments passed to the script ${#@} The number of command-line arguments passed to the script? The return value of the $$ script's process ID (PID) $-passed to the script in the flag (using set) $_ the last parameter of the previous command $! Process ID (PID) of the last job running in the background
34. Using Cut slicing
echo 1:2:3 | Cut-d ': '-F 2echo 1:2:3 | Awk-f ': ' {' Print $ '}
35.egrep expansion
Cat 1.sh | Grep-v 5 | Grep-v 8cat 1.sh | Egrep-v ' 5|8 ' ls | Egrep ' lsit1.sh|tools.sh ' #可以同时查找多个egrep "Go?d" tools.sh #? One character * multiple characters
36.read Command with description
Read-p "uname:" Name
37.test command
#判断是否存在目录/Documents TEST-E/Home && echo OK | | Echo no["a" = = "ad"] && echo yes | | echo no# determine if parameters are equal test $a-eq $b && echo yes | | echo notest $a! = $b && echo yes | | echo no-eq equal-ne unequal test "d" = "D"-o "a" = "D" && echo yes | | Echo No-o and-A and
38. Process Tree
Ps-axjf
Linux Shell Mini Script Classic Collection