diff --git a/README.md b/README.md index a7a3f3b..9c9c37e 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,9 @@ performance of any of your sites from across the globe.
* [terminal](#tool-terminal) * [mount](#tool-mount) * [fuser](#tool-fuser) + * [ps](#tool-ps) + * [find](#tool-find) + * [diff](#tool-diff) - **[HTTP/HTTPS](#http-https)** * [curl](#tool-curl) * [httpie](#tool-httpie) @@ -265,6 +268,8 @@ performance of any of your sites from across the globe.
* [netstat](#tool-nestat) - **[Programming](#programming)** * [awk](#tool-awk) + * [sed](#tool-sed) + * [grep](#tool-grep) System @@ -276,12 +281,18 @@ performance of any of your sites from across the globe.
disown -a && exit ``` -###### Drop shell history +###### Exit without saving shell history ```bash kill -9 $$ ``` +###### Pipe stdout and stderr to separate commands + +```bash +some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr) +``` + ###### List of commands you use most often ```bash @@ -307,6 +318,12 @@ vim scp://user@host//etc/fstab ``` ___ +###### Create a directory and change into it at the same time + +```bash +mkd () { mkdir -p "$@" && cd "$@"; } +``` + ##### Tool: [mount](https://curl.haxx.se) ###### Mount a temporary ram partition @@ -328,6 +345,42 @@ ___ fuser -k filename ``` +___ + +##### Tool: [ps](https://curl.haxx.se) + +###### Show a 4-way scrollable process tree with full details + +```bash +ps awwfux | less -S +``` + +___ + +##### Tool: [find](https://curl.haxx.se) + +###### Find files that have been modified on your system in the past 60 minutes + +```bash +find / -mmin 60 -type f +``` + +###### Find all files larger than 20M + +```bash +find / -type f -size +20M +``` + +___ + +##### Tool: [diff](https://curl.haxx.se) + +###### Compare two directory trees + +```bash +diff <(cd directory1 && find | sort) <(cd directory2 && find | sort) +``` + HTTP/HTTPS ##### Tool: [curl](https://curl.haxx.se) @@ -398,6 +451,16 @@ ssh user@host cat /path/to/remotefile | diff /path/to/localfile - ssh -t reachable_host ssh unreachable_host ``` +###### Run command over ssh on remote host + +```bash +cat > cmd.txt << __EOF__ +cat /etc/hosts +__EOF__ + +ssh host -l user $(` - communicates with the specified peer socket * `filename` - define socket +___ + ##### Tool: [lsof](http://www.dest-unreach.org/socat/doc/socat.html/) ###### Show process that use internet connection at the moment @@ -676,6 +741,18 @@ socat TCP-LISTEN:1234,bind=127.0.0.1,reuseaddr,fork,su=nobody,range=127.0.0.0/8 lsof -P -i -n ``` +###### Show process that use specific port number + +```bash +lsof -i tcp:443 +``` + +###### Lists all listening ports together with the PID of the associated process + +```bash +lsof -Pan -i tcp -i udp +``` + **Tool: [netstat](http://www.dest-unreach.org/socat/doc/socat.html/)** ###### Graph # of connections for each hosts @@ -693,3 +770,42 @@ netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | grep ```bash awk '!x[$0]++' filename ``` + +###### Exclude multiple columns using AWK + +```bash +awk '{$1=$3=""}1' filename +``` + +___ + +##### Tool: [sed](http://www.dest-unreach.org/socat/doc/socat.html/) + +###### To print a specific line from a file + +```bash +sed -n 10p /path/to/file +``` + +###### Remove a specific line from a file + +```bash +sed -i 10d /path/to/file +``` + +___ + +##### Tool: [grep](http://www.dest-unreach.org/socat/doc/socat.html/) + +###### Search for a "pattern" inside all files in the current directory + +```bash +grep -RnisI "pattern" * +fgrep "pattern" * -R +``` + +###### Remove blank lines from a file and save output to new file + +```bash +grep . filename > newfilename +```