shell terminal
- !!the previous command (Actually the latest command list with command- history)- !-1is equal to- !!- !-2is second command list with command- history- !^first parameter- !:1first parameter- !:nthe n parameter- !:$last parameter
- C-A/Ejump to the head/end position- C-U/Ktrim to head/tail- C-P/Nprev/next command- C-Rhistory command- C--zoom in- C-Lclear screen, same as- clear- C-Ccancel current command- C-&cancel modify- C-Tswitch- C-Ypaste- C-Wdelete a word
 Below operation need to unset Enable menu access keys option of terminal.- C-f/bmove cursor forward/backward a character- M-f/bmove cursor forward/backward a word- C-ddelete a character forward- C-hdelete a character backward- M-ddelete a word froward- C-M-hdelete a word backward, the word was splited by any special symbols- C-wdelete a word backward, the word was splited by space symbol only- C-]search character forward- C-M-]search character backward
- <alt>+.get the last parameter of previous command
common command
- cd -switch to last dir- cdswitch to user home dir
- cp filename{,.bak}a fast method to bakup a file
- mv filename{.bak,}a fast method to cut the suffix
- time commandcount the elapsed time
- mount -t cifs -o username=***,passwd=*** //ip/path /mnt/test
 mount network sharing dir- mount -t iso9660 /mnt/iso/FC17-DVD.iso /mnt/dvd
 use for mounting ISO file- mount --bind /root/project/myprj /root/x86_64_build/source
 mount a dir to another, use for across-compilation mostly- mount -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 dir- tar tvf example.tar.gzlist the contents of an archive- tar -zcvf - stuff | openssl des3 -salt -k *** | dd of=stuff.des3encryption- tar cvfz chenxu.tar.gz dir --exclude dir/dir1 --exclude dir/dir2/dir3- tar -xvf 1425279081.tar.gz var/log/messageget only one file- dd if=stuff.des3 | openssl des3 -d -k *** | tar zxf -decryption- 7z a -t7z -ptestpsw123 mytest.7z -r testfolder/*zip folder and encrypt it by 7z
- getconf LONG_BITprint the operator system bits- grep -c "lm" /proc/cpuinfoif output is not 0, it is 64bit cpu
- du -sh- du -s * |sort -n |tail
- free 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 direactorys- find . \( -path ./.git -o -path dir2 \) -prune -o -type d -printsearch sub-dir, except .git and dir2- find /usr/include/ -path /usr/include/boost -prune -o -name '*.h' -print >1.txt- find . -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 files- find ./ \( -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 path- find /usr -size +100Mfind file size larger than 100M- find /home -mtime +120- find /var \! -atime -90- find <dir> -executable -type fonly find executable files
- grep -r "abc" /root/source- grep -r --include "*.h" "date" path- grep -m 1 "model name" /proc/cpuinfoonly display the first match line- grep -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-match- grep -w "linux" *.mdmatch word- grep -rl --include=*.{h,cpp} "socket" .search socket only with .h .cpp files- grep --exclude-dir="_posts" --exclude-dir="_site" -r "Dennis" ./exclude specify directory- grep -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°C
- history|awk '{print $2}'|awk 'begin {FS="|"} {print $1}'|sort|uniq -c|sort -rn|head -10
- ps aux | sort -nk +4 | tail- ps -eo pid,lstart,etime | grep 3208view the start and running time of specify process.- ps axjfprint process tree- ps -efsee every process- ps -eLfget about thread info- ps -U root -u root usee every process running as root- pgrep firefoxprint the procee id of firefox
- uname -a
- whereis cp- rpm -qf /usr/bin/cp- rpm -ivp ***.rpm
- rpm -qpl packetnamelist files- rpm -i --relocatechange install directory- rpm -qa |grep XXXcheck whether XXX was installed- rpm -e $(rpm -qf $(which teamviewer))remove software
- mkdir -p /test/dir1/dir2/dir3
- ftp 192.168.1.102 2121- pwdview remote directory- lcdchange to the local directory- !lslist local files- put 1.jpg- get 2.jpg- mput *.jpg- mget *.jpgdownload multiple files- bye
- wget ftp://IP:PORT/* --ftp-user=xxx --ftp-password=xxx -rsupport download
 multiple files and directories, good to replace- ftp
awk and sed
- awk - awk FS'' 'condition1{operator1}condition2{operator2}...' filename
 NR:number row, NF:number field- awk '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 file- awk -F'=' '/HWADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0
- sed - sed [options] 'command' file(s)- sed [options] -f scriptfile file(s)- sed -i '/'$prj'/{s/\(.*#.*#\)[0-9]\+/\1'$rev_new'/}' $conf_file- sed -n 10,23p filepath-n print the specific lines- sed 'N;s/\n/ /' filepathjoin two line into one- echo -e "11\n22\n33\n" | sed -n '/22/{n;p}'print next line after match- sed ':a;N;s/\n/ /;ba;' filejoin all lines
git and svn
- git - git clone url- git add .- git commit -m "***"- git commit file -m "***"- git push origin master- git status- git diff- git rm ***remove file- git rm -r ***remove directory- git pull- git mv *** ###- git remote -vshow remote repository info- git reset <file>undo git add- git checkout HEAD /path/fileundo git rm on one file- git rm $(git ls-files --deleted)undo git rm multiple files
- svn - svn list url- svn co url- svn status- svn update- svn info url- svn di- svn di -r ver1:ver2- svn di -r ver1:ver2 path- svn revert [-R] path- svn merge -r ver2:ver1 path- svn log -r ver1:ver2- svn log -l5show 5 latest logs- svn add path- svn commit -m "***"- svn ci path -m "***"- ls ~/.subversion/auth/svn.simpleuser information location
network
- ip addr- cat /sys/class/net/eth{0,1}/addressdisplay mac address- ip addr add 172.16.60.69/24 dev eth1
- ifconfig eth0 down; ifconfig eth0 hw ether MAC_ADDR; ifconfig eth0 upchange MAC address- ifconfig eth2 192.168.1.102 netmask 255.255.255.0 upadd ip address for eth2- ifconfig eth2:1 192.168.1.23 netmask 255.255.255.0 upadd another ip for eth2- ifconfig eth0 mtu 6000set MTU
- ping -I 192.16.4.23 192.16.4.70set source address to specified interface address
- route add default gw 172.16.130.1 eth2- route del default gw 172.16.130.1 eth2- route add -host 192.168.168.110 dev eth0- route del -host 192.168.168.110 dev eth0- route add -net 172.16.130.0/24 gw 172.16.130.1 eth2- route del -net 172.16.0.0 netmask 255.255.0.0 dev eth0- ip route flush cache
- python -m SimpleHTTPServer- python -m http.serverfor windows
- ssh root@172.168.1.101
- ssh -f -NC -D7070 user@shell.cjb.netssh tunnel- ssh -f -NC -D7070 user@216.194.70.6ssh tunnel
- scp abc.sh root@172.168.1.101:/root/testupload file- scp root@172.168.1.101:/root/test/abc.sh /root/mytestdownload file- sshpass -p passwd scp abc.sh root@172.168.1.101:/root/test
- nmap ip- nmap 192.168.1.1 -p 8000check the port is open or not- nmap -v -sn 192.168.1.1/24- nmap -v -sn 192.168.1.1/24 |grep 'report' |grep -v 'down' |awk '{print $NF}'scan local alive ip
- nc -z -w 1 IP PORT- nc -z -w 1 192.168.1.1 100- nc -z -w 1 -u 192.168.1.1 100- nc -z -w 1 192.168.1.100 1-65535scan all ports from 1 to 65535
- lsof -i:111- netstat -apn | grep 111- iptables -Llist rules- iptables -L INPUT --line-numbers- iptables -A INPUT -p tcp --dport 111 -j DROPforbid specific port- iptables -A OUTPUT -p tcp --dport 111 -j DROP- iptables -A INPUT -p tcp --dport 8024 -j ACCEPTall rule, allow port 8024- iptables -I INPUT 5 -p tcp --dport 8024 -j ACCEPTadd rule to specify position(5)- iptables -D INPUT -p tcp --dport 8024 -j ACCEPTdelete rule- service iptables save- service iptables stop- service iptables start
- curl ifconfig.me- curl ipinfo.io/IP_ADDRESSget geographic location of an IP address
- geoiplookup IP_ADDRESS
- dig domain- dig -x host
- netstat -nlpview service and listen ports- netstat -nptview tcp connections- netstat -sdisplay networking statistics
- wget urldownload file- wget -m -p -np -k -E http://site/path/mirror the site- wget -A pdf,jpg -m -p -np -k -E http://site/path/only download pdf and jpg file- wget url_file -O new_name.filerename
- tcpdump -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.pcap- tcpdump -l | tee dat- tcpdump -U host 172.16.130.88 and port 3260 -w tcpdump.pcapflush each packet to packet-buffered- tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)- tcpdump -i eth0 src host hostname- tcpdump -i eth0 dst host hostname- tcpdump -n -e -i eth0 icmp- tcpdump -n -e icmp- tcpdump -n -e arp
- telnet 172.16.50.39 3128check port is available or not
- arp -a
- squid -CNd1
- traceroute www.baidu.comdisplay all the route from my host to the website
os
- FedoraAlt+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 -y- yum search XXX- yum remove XXX- yum clean all- yum 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 description- man 2 open,- man 2 read,- man 2 write,- man 2 fork- man 3 errnoview error number description- man 3 printf- man ascii
Others
- vimdiff a.log b.logdiff two files- vim -b fileedit binary file, use- :%!xxdand- :%!xxd -r
- diff /tmp/test01 /tmp/test02compare file in two directory- diff -r /tmp/test01 /tmp/test02compare file in directory and subdirectory- diff /tmp/test01/1.c /tmp/test02/2.ccompare two files
- patchdiff a.c b.c > c.patchpatch a.c c.patch
- vmstat iostat ifstat nload top hexdump od- hexdump -C filenamedisplay hex+ASCII of file- iostat -x 2 5- ipcsshow all ipc info- nloadmonitor network traffic, use- tabkey to switch to next interface, and- qto quit.
- dd if=/dev/zero of=$test_file bs=1M count=$dev_size 2>> $log- dd of=/dev/sdh of=/dev/zero bs=1M count=500 oflag=directtest the real hard disk speed- dd 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.txt
- watch -n 5 command
- chroot .
- date "+%F %R:%S"- date "+%y%m%d%H%M%S"- date +%sprint timestamp of current time- date -d @1420210697translate timestamp to datetime- date +%s -d"Jan 1, 1970 00:00:01"translate datetime to timestamp
- which executefileprint directory of executefile- ldd /usr/bin/executefileprint shared library dependencies- nm /usr/lib64/libXXX.soprint interface
- cat /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 /home- fuser -v -n tcp 7070
- echo 1 > /proc/sys/kernel/sysrqenable sysrq- echo "b" > /proc/sysrq-triggerreboot- echo "o" > /proc/sysrq-triggershutdown- shutdown -h nowshutdown- shutdown -h +10shutdown 10 minutes later- shutdown -h 10:00shutdown at ten clock
- dmidecode | more: view mainboard info- cat /proc/cpuinfo: view CPU info- cat /proc/pci: view pci info- lspci: view PCI info- cat /proc/meminfo: view memory info- fdisk -l: view disk info- df: view disk space useage- cat /proc/interrupts: view interrupt request- dmesg | more: view device debug message
- pdftk *.pdf cat output onelargepdfile.pdfmerge pdf to one- pdftk test.pdf cat 1-3 6-20 22-end output net.pdfcut page 4,5,21 from file- qpdf --password=1234 --decrypt encrypted.pdf decrypted.pdfdecrypt pdf file- qpdf --decrypt encrypted.pdf decrypted.pdffor empty password
- vi -e -s -c ":%s/pattern/string/g" -c ":wq" fileexecute vi comand in shell
- format u diskfdisk -l: find u diskumount /dev/sdb1: umount u diskmkfs.vfat /dev/sdb1: format as fat
- history -cclean- history -d offsetdelete specify command
- convert -resize 1024x768 input.svg output.pngconvert svg to png- convert file.pdf file.pngconvert pdf to images(file-XX.png)- convert *.png file.pdfconvert images to one pdf- convert -fill green -pointsize 40 -draw 'text 10,50 "funny day"' foo.png comment.pngadd text to picture
- import foo.pngcapture a select rectangular
- for i inls- ; do mv -f $iecho $i | sed ‘s/^………/iscsi/‘- ; donerename
 files, replace the first 5 characters with- iscsi
- fc-listlist fonts
- strace -o 1.log -s 1024 -T -tt -p 1234print the system call and time used for process 1234
- printfformat and print data- printf '%x\n' 1550convert octal value 1550 to hex, output 60e- printf '%d\n' 0x99convert hex value 0x99 to octal, output 153
- echo "51200000/64/3“ |bc -lcalculate
- echo 'abc 123dd 3xxx tt' |tr -s '[:space:]' '\n'translate spaces to be line break symbol- echo '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 password- unzip -Phq.hzy.zf.xf.hx.l@123 test.zipunzip zip file with password- unzip -Z test.zipunzip file without password- cat abc.zip.00* >abc.zipmerge zip files
- pkill -9 -t pts/1
- setenforce 0forbid Selinux temporary- sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/configforbid Selinux, need reboot
- kill PID- kill -9 PID- kill -kill PID
- vgchange -ay
- lsof |grep '/core/messages'find which application open the specify file
- for 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 intervals
- echo export LANG=en_US.utf8 >>~/.profile, set lang for os, and checking with- echo $LANGor- locale
- gstack threadID
- rm !(*.pdf)remove files except pdf
- [! -d /temp/test] && mkdir /tmp/testif folder not exist, create it.