shell terminal
!!the previous command (Actually the latest command list with commandhistory)!-1is equal to!!!-2is second command list with commandhistory!^first parameter!:1first parameter!:nthe n parameter!:$last parameterC-A/Ejump to the head/end positionC-U/Ktrim to head/tailC-P/Nprev/next commandC-Rhistory commandC--zoom inC-Lclear screen, same asclearC-Ccancel current commandC-&cancel modifyC-TswitchC-YpasteC-Wdelete a word
Below operation need to unset Enable menu access keys option of terminal.C-f/bmove cursor forward/backward a characterM-f/bmove cursor forward/backward a wordC-ddelete a character forwardC-hdelete a character backwardM-ddelete a word frowardC-M-hdelete a word backward, the word was splited by any special symbolsC-wdelete a word backward, the word was splited by space symbol onlyC-]search character forwardC-M-]search character backward<alt>+.get the last parameter of previous command
common command
cd -switch to last dircdswitch to user home dircp filename{,.bak}a fast method to bakup a filemv filename{.bak,}a fast method to cut the suffixtime commandcount the elapsed timemount -t cifs -o username=***,passwd=*** //ip/path /mnt/test
mount network sharing dirmount -t iso9660 /mnt/iso/FC17-DVD.iso /mnt/dvd
use for mounting ISO filemount --bind /root/project/myprj /root/x86_64_build/source
mount a dir to another, use for across-compilation mostlymount -t tmpfs -o size=1024m tmpfs /mnt/ram
mount memory as a w/r dir (use for high speed I/O operation, and disk space not enough)tar xvf example.tar.gz -C /root/testextract files to specific dirtar tvf example.tar.gzlist the contents of an archivetar -zcvf - stuff | openssl des3 -salt -k *** | dd of=stuff.des3encryptiontar cvfz chenxu.tar.gz dir --exclude dir/dir1 --exclude dir/dir2/dir3tar -xvf 1425279081.tar.gz var/log/messageget only one filedd if=stuff.des3 | openssl des3 -d -k *** | tar zxf -decryption7z a -t7z -ptestpsw123 mytest.7z -r testfolder/*zip folder and encrypt it by 7zgetconf LONG_BITprint the operator system bitsgrep -c "lm" /proc/cpuinfoif output is not 0, it is 64bit cpudu -shdu -s * |sort -n |tailfree bg kill pid killall proc chmod 777 (r:4,w:2,x:1)(user,group,all)find / -name "***"find path \( -name "*.h" -or -name "*.c" \) -exec grep -in "***" {} \;find ./ -name "*.*" -exec ls -l {} \; |awk '{print $5,$9}' |sort -n |tailfind the 10 biggest files.find / -type d -name "gedit"search direactorysfind . \( -path ./.git -o -path dir2 \) -prune -o -type d -printsearch sub-dir, except .git and dir2find /usr/include/ -path /usr/include/boost -prune -o -name '*.h' -print >1.txtfind . -name ".svn" | xargs rm -rffind .svn folder in current directory, and remove it.find ./ \( -name "*.h" -or -name "*.c" \) -exec wc -l {} \; | awk '{s+=$1} END {print s}'count lines of specify filesfind ./ \( -name "*.h" -or -name "*.c" \) | xargs wc -l | tail -n 1count lines of specify files
the upon two command can count lines of specify files, but what is the
difference of them, look this
Difference xargs and exec
you will find the answer.find ./ -path ./perl -prune -o -name "*.so" -exec cp {} ../net-snmp-5.4.4-sdk/lib/ \;
copy files which search by find, search exclude ./perl pathfind /usr -size +100Mfind file size larger than 100Mfind /home -mtime +120find /var \! -atime -90find <dir> -executable -type fonly find executable filesgrep -r "abc" /root/sourcegrep -r --include "*.h" "date" pathgrep -m 1 "model name" /proc/cpuinfoonly display the first match linegrep -i -E "abc|123"match abc or 123, -i ignore, -E extended regular expression.grep -r -l "main" .search all files under each directory, -l files-with-match, -L files-withou-matchgrep -w "linux" *.mdmatch wordgrep -rl --include=*.{h,cpp} "socket" .search socket only with .h .cpp filesgrep --exclude-dir="_posts" --exclude-dir="_site" -r "Dennis" ./exclude specify directorygrep -rni '[^a-zA-Z]abc[^a-zA-Z]' ./match like “tt.abc.1234”, not match like “ttabccd”cut -d"" -f1
e.g:[root@localhost ~]# sensors |grep "Core "
Core 0: +30.0°C (high = +76.0°C, crit = +100.0°C)
Core 1: +37.0°C (high = +76.0°C, crit = +100.0°C)[root@localhost ~]# sensors |grep "Core " |cut -d"+" -f2 |cut -d" " -f1
30.0°C
37.0°Chistory|awk '{print $2}'|awk 'begin {FS="|"} {print $1}'|sort|uniq -c|sort -rn|head -10ps aux | sort -nk +4 | tailps -eo pid,lstart,etime | grep 3208view the start and running time of specify process.ps axjfprint process treeps -efsee every processps -eLfget about thread infops -U root -u root usee every process running as rootpgrep firefoxprint the procee id of firefoxuname -awhereis cprpm -qf /usr/bin/cprpm -ivp ***.rpmrpm -qpl packetnamelist filesrpm -i --relocatechange install directoryrpm -qa |grep XXXcheck whether XXX was installedrpm -e $(rpm -qf $(which teamviewer))remove softwaremkdir -p /test/dir1/dir2/dir3ftp 192.168.1.102 2121pwdview remote directorylcdchange to the local directory!lslist local filesput 1.jpgget 2.jpgmput *.jpgmget *.jpgdownload multiple filesbyewget ftp://IP:PORT/* --ftp-user=xxx --ftp-password=xxx -rsupport download
multiple files and directories, good to replaceftp
awk and sed
awk
awk FS'' 'condition1{operator1}condition2{operator2}...' filename
NR:number row, NF:number fieldawk 'NR==1{print $0}'arr=($(awk -F'#' '{print $1,$2,$3,$4}' $conf_file))ps aux | awk 'NR==1{print $0}$3>10{print $0}'awk -F'<|>' '{if(NF>3){print $2 ":" $3}}' /tmp/test.xmlparse xml fileawk -F'=' '/HWADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0sed
sed [options] 'command' file(s)sed [options] -f scriptfile file(s)sed -i '/'$prj'/{s/\(.*#.*#\)[0-9]\+/\1'$rev_new'/}' $conf_filesed -n 10,23p filepath-n print the specific linessed 'N;s/\n/ /' filepathjoin two line into oneecho -e "11\n22\n33\n" | sed -n '/22/{n;p}'print next line after matchsed ':a;N;s/\n/ /;ba;' filejoin all lines
git and svn
git
git clone urlgit add .git commit -m "***"git commit file -m "***"git push origin mastergit statusgit diffgit rm ***remove filegit rm -r ***remove directorygit pullgit mv *** ###git remote -vshow remote repository infogit reset <file>undo git addgit checkout HEAD /path/fileundo git rm on one filegit rm $(git ls-files --deleted)undo git rm multiple filessvn
svn list urlsvn co urlsvn statussvn updatesvn info urlsvn disvn di -r ver1:ver2svn di -r ver1:ver2 pathsvn revert [-R] pathsvn merge -r ver2:ver1 pathsvn log -r ver1:ver2svn log -l5show 5 latest logssvn add pathsvn commit -m "***"svn ci path -m "***"ls ~/.subversion/auth/svn.simpleuser information location
network
ip addrcat /sys/class/net/eth{0,1}/addressdisplay mac addressip addr add 172.16.60.69/24 dev eth1ifconfig eth0 down; ifconfig eth0 hw ether MAC_ADDR; ifconfig eth0 upchange MAC addressifconfig eth2 192.168.1.102 netmask 255.255.255.0 upadd ip address for eth2ifconfig eth2:1 192.168.1.23 netmask 255.255.255.0 upadd another ip for eth2ifconfig eth0 mtu 6000set MTUping -I 192.16.4.23 192.16.4.70set source address to specified interface addressroute add default gw 172.16.130.1 eth2route del default gw 172.16.130.1 eth2route add -host 192.168.168.110 dev eth0route del -host 192.168.168.110 dev eth0route add -net 172.16.130.0/24 gw 172.16.130.1 eth2route del -net 172.16.0.0 netmask 255.255.0.0 dev eth0ip route flush cachepython -m SimpleHTTPServerpython -m http.serverfor windowsssh root@172.168.1.101ssh -f -NC -D7070 user@shell.cjb.netssh tunnelssh -f -NC -D7070 user@216.194.70.6ssh tunnelscp abc.sh root@172.168.1.101:/root/testupload filescp root@172.168.1.101:/root/test/abc.sh /root/mytestdownload filesshpass -p passwd scp abc.sh root@172.168.1.101:/root/testnmap ipnmap 192.168.1.1 -p 8000check the port is open or notnmap -v -sn 192.168.1.1/24nmap -v -sn 192.168.1.1/24 |grep 'report' |grep -v 'down' |awk '{print $NF}'scan local alive ipnc -z -w 1 IP PORTnc -z -w 1 192.168.1.1 100nc -z -w 1 -u 192.168.1.1 100nc -z -w 1 192.168.1.100 1-65535scan all ports from 1 to 65535lsof -i:111netstat -apn | grep 111iptables -Llist rulesiptables -L INPUT --line-numbersiptables -A INPUT -p tcp --dport 111 -j DROPforbid specific portiptables -A OUTPUT -p tcp --dport 111 -j DROPiptables -A INPUT -p tcp --dport 8024 -j ACCEPTall rule, allow port 8024iptables -I INPUT 5 -p tcp --dport 8024 -j ACCEPTadd rule to specify position(5)iptables -D INPUT -p tcp --dport 8024 -j ACCEPTdelete ruleservice iptables saveservice iptables stopservice iptables startcurl ifconfig.mecurl ipinfo.io/IP_ADDRESSget geographic location of an IP addressgeoiplookup IP_ADDRESSdig domaindig -x hostnetstat -nlpview service and listen portsnetstat -nptview tcp connectionsnetstat -sdisplay networking statisticswget urldownload filewget -m -p -np -k -E http://site/path/mirror the sitewget -A pdf,jpg -m -p -np -k -E http://site/path/only download pdf and jpg filewget url_file -O new_name.filerenametcpdump -Dlist available device(run as root)tcpdump -i p4p1 host 172.16.130.88 and port 80 -nuse specify interface “p4p1”tcpdump -i p4p1 host 172.16.130.88 and port 3260 -w tcpdump.pcaptcpdump -l | tee dattcpdump -U host 172.16.130.88 and port 3260 -w tcpdump.pcapflush each packet to packet-bufferedtcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)tcpdump -i eth0 src host hostnametcpdump -i eth0 dst host hostnametcpdump -n -e -i eth0 icmptcpdump -n -e icmptcpdump -n -e arptelnet 172.16.50.39 3128check port is available or notarp -asquid -CNd1traceroute www.baidu.comdisplay all the route from my host to the website
os
- Fedora
Alt+Tabswitch windowsAlt+`switch sub-windowsWinwindows key, use to show all applicationWin->Space, search application - yum use local repository
- mount iso file to /mnt/cdrom
- modify /etc/yum.repos.d/CentOS-Media.repo, add text “file:///mnt/cdrom/“
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
gdgcheck=1file:///media/cdrom/ file:///media/cdrecorder/ file:///mnt/cdrom/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
yum install XXX -yyum search XXXyum remove XXXyum clean allyum makecache- Ubuntu
reset root password, press ‘e’ to edit grub boot option, change ‘ro quiet splash’
to ‘rw init=/bin/bash’, then login terminal with root, use ‘passwd’ to reset. - Ubuntu remove software
- dpkg –get-selections | grep ‘software-name’
- sudo apt-get remove –purge software_name
- dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P
vimperator(Firfox plugin)
- vimperator
:helpOpen help page:helpallShow all help on one pageC-[cancel command modedclose current pageuundo close current page/searchHGo back in the browser historyggGo to the top of the pageGGo to the bottom of the pageC-fforward pageC-bbackward pageyCopy the current URL to clipboadpOpen the URL from current clipboad contents in current bufferPOpen the URL from current clipboad contents in a new tab bufferrReload current pageZZQuit and save the sessionC-nGo to the next bufferC-pGo to the previous buffergiGo to input fieldg-uGo to the parent directoryg-UGo to the root of the websitecStart caret mode.Like normal mode of vim, useh j k lto move, and
pressvto start visual mode, then pressyto copy select textgiUse [count]gi to Focus to the [count]th input fieldC-lGo to URL editor and select itC-tOpen a new tab
program
man 2 sys_call_nameview system call function descriptionman 2 open,man 2 read,man 2 write,man 2 forkman 3 errnoview error number descriptionman 3 printfman ascii
Others
vimdiff a.log b.logdiff two filesvim -b fileedit binary file, use:%!xxdand:%!xxd -rdiff /tmp/test01 /tmp/test02compare file in two directorydiff -r /tmp/test01 /tmp/test02compare file in directory and subdirectorydiff /tmp/test01/1.c /tmp/test02/2.ccompare two files- patch
diff a.c b.c > c.patchpatch a.c c.patch vmstat iostat ifstat nload top hexdump odhexdump -C filenamedisplay hex+ASCII of fileiostat -x 2 5ipcsshow all ipc infonloadmonitor network traffic, usetabkey to switch to next interface, andqto quit.dd if=/dev/zero of=$test_file bs=1M count=$dev_size 2>> $logdd of=/dev/sdh of=/dev/zero bs=1M count=500 oflag=directtest the real hard disk speeddd if=path/Fedora-os.iso of=/dev/sdbinstall fedora live os to U disk(make
sure the mount directory of U disk is /dev/sdb, if not should change the out file directory)> file.txtwatch -n 5 commandchroot .date "+%F %R:%S"date "+%y%m%d%H%M%S"date +%sprint timestamp of current timedate -d @1420210697translate timestamp to datetimedate +%s -d"Jan 1, 1970 00:00:01"translate datetime to timestampwhich executefileprint directory of executefileldd /usr/bin/executefileprint shared library dependenciesnm /usr/lib64/libXXX.soprint interfacecat /proc/uptime | awk -F. '{d=($1/86400);h=($1%86400)/3600;m=($1%3600)/60;s=($1%60);printf("system had run %d day %d hours %d mins %d secs\n",d,h,m,s)}'fuser -u /homefuser -v -n tcp 7070echo 1 > /proc/sys/kernel/sysrqenable sysrqecho "b" > /proc/sysrq-triggerrebootecho "o" > /proc/sysrq-triggershutdownshutdown -h nowshutdownshutdown -h +10shutdown 10 minutes latershutdown -h 10:00shutdown at ten clockdmidecode | more: view mainboard infocat /proc/cpuinfo: view CPU infocat /proc/pci: view pci infolspci: view PCI infocat /proc/meminfo: view memory infofdisk -l: view disk infodf: view disk space useagecat /proc/interrupts: view interrupt requestdmesg | more: view device debug messagepdftk *.pdf cat output onelargepdfile.pdfmerge pdf to onepdftk test.pdf cat 1-3 6-20 22-end output net.pdfcut page 4,5,21 from fileqpdf --password=1234 --decrypt encrypted.pdf decrypted.pdfdecrypt pdf fileqpdf --decrypt encrypted.pdf decrypted.pdffor empty passwordvi -e -s -c ":%s/pattern/string/g" -c ":wq" fileexecute vi comand in shell- format u disk
fdisk -l: find u diskumount /dev/sdb1: umount u diskmkfs.vfat /dev/sdb1: format as fat history -ccleanhistory -d offsetdelete specify commandconvert -resize 1024x768 input.svg output.pngconvert svg to pngconvert file.pdf file.pngconvert pdf to images(file-XX.png)convert *.png file.pdfconvert images to one pdfconvert -fill green -pointsize 40 -draw 'text 10,50 "funny day"' foo.png comment.pngadd text to pictureimport foo.pngcapture a select rectangularfor i inls; do mv -f $iecho $i | sed ‘s/^………/iscsi/‘; donerename
files, replace the first 5 characters withiscsifc-listlist fontsstrace -o 1.log -s 1024 -T -tt -p 1234print the system call and time used for process 1234printfformat and print dataprintf '%x\n' 1550convert octal value 1550 to hex, output 60eprintf '%d\n' 0x99convert hex value 0x99 to octal, output 153echo "51200000/64/3“ |bc -lcalculateecho 'abc 123dd 3xxx tt' |tr -s '[:space:]' '\n'translate spaces to be line break symbolecho 'abc 123dT 3xXX tt' |tr '[:upper:]' '[:lower:]'cat test.md |tr -s '[:space:]' '\n' |tr '[:upper:]' '[:lower:]' |sort |uniq -c| sort -nr |head -10
find the top hot words for text document.zip -Phq.hzy.zf.xf.hx.l@123 test.zip testzip “test” file to be test.zip using passwordunzip -Phq.hzy.zf.xf.hx.l@123 test.zipunzip zip file with passwordunzip -Z test.zipunzip file without passwordcat abc.zip.00* >abc.zipmerge zip filespkill -9 -t pts/1setenforce 0forbid Selinux temporarysed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/configforbid Selinux, need rebootkill PIDkill -9 PIDkill -kill PIDvgchange -aylsof |grep '/core/messages'find which application open the specify filefor x inseq 1 1 10; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done
print the processes in a “D” state every 5 seconds for 10 intervalsecho export LANG=en_US.utf8 >>~/.profile, set lang for os, and checking withecho $LANGorlocalegstack threadIDrm !(*.pdf)remove files except pdf[! -d /temp/test] && mkdir /tmp/testif folder not exist, create it.