shell terminal
!!
the previous command (Actually the latest command list with commandhistory
)!-1
is equal to!!
!-2
is second command list with commandhistory
!^
first parameter!:1
first parameter!:n
the n parameter!:$
last parameterC-A/E
jump to the head/end positionC-U/K
trim to head/tailC-P/N
prev/next commandC-R
history commandC--
zoom inC-L
clear screen, same asclear
C-C
cancel current commandC-&
cancel modifyC-T
switchC-Y
pasteC-W
delete a word
Below operation need to unset Enable menu access keys option of terminal.C-f/b
move cursor forward/backward a characterM-f/b
move cursor forward/backward a wordC-d
delete a character forwardC-h
delete a character backwardM-d
delete a word frowardC-M-h
delete a word backward, the word was splited by any special symbolsC-w
delete 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 dircd
switch to user home dircp filename{,.bak}
a fast method to bakup a filemv filename{.bak,}
a fast method to cut the suffixtime command
count 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/test
extract files to specific dirtar tvf example.tar.gz
list the contents of an archivetar -zcvf - stuff | openssl des3 -salt -k *** | dd of=stuff.des3
encryptiontar cvfz chenxu.tar.gz dir --exclude dir/dir1 --exclude dir/dir2/dir3
tar -xvf 1425279081.tar.gz var/log/message
get 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_BIT
print the operator system bitsgrep -c "lm" /proc/cpuinfo
if output is not 0, it is 64bit cpudu -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 |tail
find the 10 biggest files.find / -type d -name "gedit"
search direactorysfind . \( -path ./.git -o -path dir2 \) -prune -o -type d -print
search sub-dir, except .git and dir2find /usr/include/ -path /usr/include/boost -prune -o -name '*.h' -print >1.txt
find . -name ".svn" | xargs rm -rf
find .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 1
count 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 +100M
find file size larger than 100Mfind /home -mtime +120
find /var \! -atime -90
find <dir> -executable -type f
only find executable filesgrep -r "abc" /root/source
grep -r --include "*.h" "date" path
grep -m 1 "model name" /proc/cpuinfo
only 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" *.md
match 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 -10
ps aux | sort -nk +4 | tail
ps -eo pid,lstart,etime | grep 3208
view the start and running time of specify process.ps axjf
print process treeps -ef
see every processps -eLf
get about thread infops -U root -u root u
see every process running as rootpgrep firefox
print the procee id of firefoxuname -a
whereis cp
rpm -qf /usr/bin/cp
rpm -ivp ***.rpm
rpm -qpl packetname
list filesrpm -i --relocate
change install directoryrpm -qa |grep XXX
check whether XXX was installedrpm -e $(rpm -qf $(which teamviewer))
remove softwaremkdir -p /test/dir1/dir2/dir3
ftp 192.168.1.102 2121
pwd
view remote directorylcd
change to the local directory!ls
list local filesput 1.jpg
get 2.jpg
mput *.jpg
mget *.jpg
download multiple filesbye
wget ftp://IP:PORT/* --ftp-user=xxx --ftp-password=xxx -r
support 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.xml
parse xml fileawk -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 linessed 'N;s/\n/ /' filepath
join two line into oneecho -e "11\n22\n33\n" | sed -n '/22/{n;p}'
print next line after matchsed ':a;N;s/\n/ /;ba;' file
join 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 filegit rm -r ***
remove directorygit pull
git mv *** ###
git remote -v
show remote repository infogit reset <file>
undo git addgit checkout HEAD /path/file
undo git rm on one filegit rm $(git ls-files --deleted)
undo git rm multiple filessvn
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 -l5
show 5 latest logssvn add path
svn commit -m "***"
svn ci path -m "***"
ls ~/.subversion/auth/svn.simple
user information location
network
ip addr
cat /sys/class/net/eth{0,1}/address
display mac addressip addr add 172.16.60.69/24 dev eth1
ifconfig eth0 down; ifconfig eth0 hw ether MAC_ADDR; ifconfig eth0 up
change MAC addressifconfig eth2 192.168.1.102 netmask 255.255.255.0 up
add ip address for eth2ifconfig eth2:1 192.168.1.23 netmask 255.255.255.0 up
add another ip for eth2ifconfig eth0 mtu 6000
set MTUping -I 192.16.4.23 192.16.4.70
set source address to specified interface addressroute 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.server
for windowsssh root@172.168.1.101
ssh -f -NC -D7070 user@shell.cjb.net
ssh tunnelssh -f -NC -D7070 user@216.194.70.6
ssh tunnelscp abc.sh root@172.168.1.101:/root/test
upload filescp root@172.168.1.101:/root/test/abc.sh /root/mytest
download filesshpass -p passwd scp abc.sh root@172.168.1.101:/root/test
nmap ip
nmap 192.168.1.1 -p 8000
check the port is open or notnmap -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 ipnc -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-65535
scan all ports from 1 to 65535lsof -i:111
netstat -apn | grep 111
iptables -L
list rulesiptables -L INPUT --line-numbers
iptables -A INPUT -p tcp --dport 111 -j DROP
forbid specific portiptables -A OUTPUT -p tcp --dport 111 -j DROP
iptables -A INPUT -p tcp --dport 8024 -j ACCEPT
all rule, allow port 8024iptables -I INPUT 5 -p tcp --dport 8024 -j ACCEPT
add rule to specify position(5)iptables -D INPUT -p tcp --dport 8024 -j ACCEPT
delete ruleservice iptables save
service iptables stop
service iptables start
curl ifconfig.me
curl ipinfo.io/IP_ADDRESS
get geographic location of an IP addressgeoiplookup IP_ADDRESS
dig domain
dig -x host
netstat -nlp
view service and listen portsnetstat -npt
view tcp connectionsnetstat -s
display networking statisticswget url
download 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.file
renametcpdump -D
list available device(run as root)tcpdump -i p4p1 host 172.16.130.88 and port 80 -n
use 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.pcap
flush 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 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 3128
check port is available or notarp -a
squid -CNd1
traceroute www.baidu.com
display all the route from my host to the website
os
- Fedora
Alt+Tab
switch windowsAlt+`
switch sub-windowsWin
windows 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
:help
Open help page:helpall
Show all help on one pageC-[
cancel command moded
close current pageu
undo close current page/
searchH
Go back in the browser historygg
Go to the top of the pageG
Go to the bottom of the pageC-f
forward pageC-b
backward pagey
Copy the current URL to clipboadp
Open the URL from current clipboad contents in current bufferP
Open the URL from current clipboad contents in a new tab bufferr
Reload current pageZZ
Quit and save the sessionC-n
Go to the next bufferC-p
Go to the previous buffergi
Go to input fieldg-u
Go to the parent directoryg-U
Go to the root of the websitec
Start caret mode.Like normal mode of vim, useh j k l
to move, and
pressv
to start visual mode, then pressy
to copy select textgi
Use [count]gi to Focus to the [count]th input fieldC-l
Go to URL editor and select itC-t
Open a new tab
program
man 2 sys_call_name
view system call function descriptionman 2 open
,man 2 read
,man 2 write
,man 2 fork
man 3 errno
view error number descriptionman 3 printf
man ascii
Others
vimdiff a.log b.log
diff two filesvim -b file
edit binary file, use:%!xxd
and:%!xxd -r
diff /tmp/test01 /tmp/test02
compare file in two directorydiff -r /tmp/test01 /tmp/test02
compare file in directory and subdirectorydiff /tmp/test01/1.c /tmp/test02/2.c
compare two files- patch
diff a.c b.c > c.patch
patch a.c c.patch
vmstat iostat ifstat nload top hexdump od
hexdump -C filename
display hex+ASCII of fileiostat -x 2 5
ipcs
show all ipc infonload
monitor network traffic, usetab
key to switch to next interface, andq
to 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=direct
test the real hard disk speeddd if=path/Fedora-os.iso of=/dev/sdb
install 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 +%s
print timestamp of current timedate -d @1420210697
translate timestamp to datetimedate +%s -d"Jan 1, 1970 00:00:01"
translate datetime to timestampwhich executefile
print directory of executefileldd /usr/bin/executefile
print shared library dependenciesnm /usr/lib64/libXXX.so
print 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 /home
fuser -v -n tcp 7070
echo 1 > /proc/sys/kernel/sysrq
enable sysrqecho "b" > /proc/sysrq-trigger
rebootecho "o" > /proc/sysrq-trigger
shutdownshutdown -h now
shutdownshutdown -h +10
shutdown 10 minutes latershutdown -h 10:00
shutdown 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.pdf
merge pdf to onepdftk test.pdf cat 1-3 6-20 22-end output net.pdf
cut page 4,5,21 from fileqpdf --password=1234 --decrypt encrypted.pdf decrypted.pdf
decrypt pdf fileqpdf --decrypt encrypted.pdf decrypted.pdf
for empty passwordvi -e -s -c ":%s/pattern/string/g" -c ":wq" file
execute vi comand in shell- format u disk
fdisk -l
: find u diskumount /dev/sdb1
: umount u diskmkfs.vfat /dev/sdb1
: format as fat history -c
cleanhistory -d offset
delete specify commandconvert -resize 1024x768 input.svg output.png
convert svg to pngconvert file.pdf file.png
convert pdf to images(file-XX.png)convert *.png file.pdf
convert images to one pdfconvert -fill green -pointsize 40 -draw 'text 10,50 "funny day"' foo.png comment.png
add text to pictureimport foo.png
capture a select rectangularfor i in
ls; do mv -f $i
echo $i | sed ‘s/^………/iscsi/‘; done
rename
files, replace the first 5 characters withiscsi
fc-list
list fontsstrace -o 1.log -s 1024 -T -tt -p 1234
print the system call and time used for process 1234printf
format and print dataprintf '%x\n' 1550
convert octal value 1550 to hex, output 60eprintf '%d\n' 0x99
convert hex value 0x99 to octal, output 153echo "51200000/64/3“ |bc -l
calculateecho '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 test
zip “test” file to be test.zip using passwordunzip -Phq.hzy.zf.xf.hx.l@123 test.zip
unzip zip file with passwordunzip -Z test.zip
unzip file without passwordcat abc.zip.00* >abc.zip
merge zip filespkill -9 -t pts/1
setenforce 0
forbid Selinux temporarysed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
forbid Selinux, need rebootkill PID
kill -9 PID
kill -kill PID
vgchange -ay
lsof |grep '/core/messages'
find which application open the specify filefor x in
seq 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 $LANG
orlocale
gstack threadID
rm !(*.pdf)
remove files except pdf[! -d /temp/test] && mkdir /tmp/test
if folder not exist, create it.