From 9abbc8eecb72df750a10db594a20e9511b46dd22 Mon Sep 17 00:00:00 2001 From: trimstray Date: Tue, 3 Jul 2018 21:09:12 +0200 Subject: [PATCH] one-liners: added new examples - signed-off-by: trimstray --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index 7d35958..9552d64 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,8 @@ performance of any of your sites from across the globe.
* [tail](#tool-tail) * [cpulimit](#tool-cpulimit) * [pwdx](#tool-pwdx) + * [tr](#tool-tr) + * [chmod](#tool-chmod) - **[HTTP/HTTPS](#http-https)** * [curl](#tool-curl) * [httpie](#tool-httpie) @@ -269,6 +271,7 @@ performance of any of your sites from across the globe.
* [socat](#tool-socat) * [lsof](#tool-lsof) * [netstat](#tool-nestat) + * [rsync](#tool-rsync) - **[Programming](#programming)** * [awk](#tool-awk) * [sed](#tool-sed) @@ -338,6 +341,12 @@ mkd () { mkdir -p "$@" && cd "$@"; } rename 'y/A-Z/a-z/' * ``` +###### Print a row of characters across the terminal + +```bash +printf "%`tput cols`s" | tr ' ' '#' +``` + ___ ##### Tool: [mount](https://curl.haxx.se) @@ -393,6 +402,12 @@ find / -mmin 60 -type f find / -type f -size +20M ``` +###### Find duplicate files (based on MD5 hash) + +```bash +find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 +``` + ___ ##### Tool: [diff](https://curl.haxx.se) @@ -419,6 +434,8 @@ tail -f file | while read; do echo "$(date +%T.%N) $REPLY"; done tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail ``` +___ + ##### Tool: [cpulimit](https://curl.haxx.se) ###### Limit the cpu usage of a process @@ -435,6 +452,8 @@ cpulimit -p pid -l 50 pwdx ``` +___ + ##### Tool: [taskset](https://curl.haxx.se) ###### Start a command on only one CPU core @@ -443,6 +462,26 @@ pwdx taskset -c 0 ``` +___ + +##### Tool: [tr](https://curl.haxx.se) + +###### Show directories in the PATH, one per line + +```bash +tr : '\n' <<<$PATH +``` + +___ + +##### Tool: [chmod](https://curl.haxx.se) + +###### Remove executable bit from all files in the current directory + +```bash +chmod -R -x+X * +``` + HTTP/HTTPS ##### Tool: [curl](https://curl.haxx.se) @@ -837,12 +876,26 @@ lsof -i tcp:443 lsof -Pan -i tcp -i udp ``` +###### List all open ports and their owning executables + +```bash +lsof -i -P | grep -i "listen" +``` + +###### Show open ports + +```bash +lsof -Pni4 | grep LISTEN | column -t +``` + ###### List all files opened by a particular command ```bash lsof -c "process" ``` +___ + **Tool: [netstat](http://www.dest-unreach.org/socat/doc/socat.html/)** ###### Graph # of connections for each hosts @@ -851,6 +904,22 @@ lsof -c "process" netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | grep -v -e '^[[:space:]]*$' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }' ``` +###### Monitor open connections for specific port including listen, count and sort it per IP + +```bash +watch "netstat -plan | grep :443 | awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1" +``` + +___ + +**Tool: [rsync](http://www.dest-unreach.org/socat/doc/socat.html/)** + +###### Rsync remote data as root using sudo + +```bash +rsync --rsync-path 'sudo rsync' username@hostname:/path/to/dir/ /local/ +``` + Programming ##### Tool: [awk](https://curl.haxx.se) @@ -883,6 +952,12 @@ sed -n 10p /path/to/file sed -i 10d /path/to/file ``` +###### Remove a range of lines from a file + +```bash +sed -i -re ',d' +``` + ___ ##### Tool: [grep](http://www.dest-unreach.org/socat/doc/socat.html/)