shell usage tips
ctrl + w
delete a word before cursorctrl + a
cursor move to beginningctrl + r
search for history commandctrl + k
delete characters after cursorctrl + u
delete the whole linectrl + e
move to the end of linectrl + b
move back one characterctrl + f
move forward one characteruse
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 levelxargs
[-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 emptycombine 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 possiblegrep
[-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 matcheslsof
[-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 filenetstat
[-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 Documentscut
[-d] delemiter
[-f] fields that want to
In hello.txt: i have a pen
cut -d ' ' -f 2,3 hello.txt
output: have a
reference: