shell usage tips
-
ctrl + w
delete a word before cursor -
ctrl + a
cursor move to beginning -
ctrl + r
search for history command -
ctrl + k
delete characters after cursor -
ctrl + u
delete the whole line -
ctrl + e
move to the end of line -
ctrl + b
move back one character -
ctrl + f
move forward one character -
use
bash -x scriptname
to debug and see what is under going
shell command
-
find
commonly used switches:
[ -name , -iname] -iname ignoring case sensitive
[-size] +20M, -5G
[-atime, -ctime, -mtime] unit is day +2 1 -3
[-amin, -cmin, -mmin] unit is minute +2 1 -3
[-type] f: regular file d: directory
[-print0] process with filename contains null character
[-maxdepth, -mindepth] find at most/least level -
xargs
[-0] process with filename contains null character
[-Ireplace_str] eg: xargs -Ifile ls -l file
[-P] how many processed to execute command, if specified with 0, run as many process as possible to deal with.
[-r] don't exec command if standard input is empty -
combine find and xargs
eg:
find /tmp -maxdepth 1 -type f -name \* -print0 | xargs -0 -P 0 -Ifile cp file ~/jk
descrption:
find all regular files in /tmp(not include subdirs) and copy them to jk directory as fast as possible -
grep
[-r] search recursively(include subdirs)
[-i] ignore case sensitive
[-w] match the whole world
[-n] print the line number that matches
[-v] invert match
[-c] count how many matches -
lsof
[-u] list all files that a user opened
[-i] list all processes that use a specific port. eg: ls -i TCP:22
[-p] list all opened files by process ID
[-c] find out files opened by some particular daemon
[lsof /path/to/file] list processes opened by specific file
- netstat
[-a] list all connections
[-t] list tcp connections
[-u] list udp connections
[-l] list sockets in listening state
[-p] show the PID and name of the program to which each socket belongs.
[netstat -tulpn] frequently used combinations
- du
[-sh] the size of a file. eg: du -sh Documents
reference:
网友评论