Last active
September 18, 2017 09:42
-
-
Save SanCoder-Q/b8f168e706b50d97ea55126b158f84f3 to your computer and use it in GitHub Desktop.
Command Magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Find out the connections of a process | |
| lsof -i -a -p <PID> | |
| # Find out the route table | |
| netstat -nr | |
| netstat -A inet -p | grep <pattern of process> | |
| # Find out the ip of a domain name | |
| nslookup <domain name> | |
| # Change the default route to local under VPN | |
| sudo route change default <local gateway> | |
| # Add route for specific ips | |
| sudo route -nv add -net <ip range> -interface <Netif> | |
| # Trace a route path to a address | |
| traceroute <address> | |
| # Dump HTTP GET with content | |
| tcpdump -X -i eth0 '(port 9091) and (tcp[(tcp[12]>>2):4] = 0x47455420)' -w dump.txt | |
| # Turn off and Turn on the Wifi | |
| networksetup -setairportpower airport off; sleep 10; networksetup -setairportpower airport on | |
| # Search one level depth with hidden files | |
| ag --depth 1 -u JAVA_HOME . | |
| # Proxy remote port to local via ssh connnection | |
| ssh -f -NTML <local_port>:<remote_domain>:<remote_port> <ssh_user>@<ssh_domain> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Examples for (GNU) cut | |
| # ==== -b, --bytes=LIST ==== | |
| echo hello | gcut -b 2 | |
| #> e | |
| echo hello | gcut -b -2 | |
| #> he | |
| echo hello | gcut -b 2,5 | |
| #> eo | |
| echo hello | gcut -b 1,3-5 | |
| #> hllo | |
| # ==== -c, --characters=LIST ==== | |
| echo 你好 | gcut -c 1 | |
| #> � ;; Not working for GNU cut | |
| echo 你好 | cut -c 1 | |
| #> 你 ;; Works fine for BSD cut | |
| # ==== -d, --delimiter ==== | |
| echo hello | gcut -dl -f1 | |
| #> he | |
| echo hello | gcut -dl -f2 | |
| #> ⏎ | |
| echo hello | gcut -dl -f3 | |
| #> o | |
| echo hello | gcut -dl -f1,3 | |
| #> helo ;; Using `l` as the output delimiter | |
| # ==== --complement ==== | |
| echo hello | gcut -b2 --complement | |
| #> hllo | |
| # ==== -s, --only-delimited ==== | |
| echo hello | gcut -da -f1 | |
| #> hello | |
| echo hello | gcut -da -f1 -s | |
| #> ⏎ | |
| # ==== --output-delimiter ==== | |
| echo hello | gcut -dl -f1,3 --output-delimiter - | |
| #> he-o | |
| # ==== -z, --zero-terminated ==== | |
| echo -e "hello\0hello" | gcut -de -f2 | |
| #> lloh | |
| echo echo -e "hello\0hello" | gcut -de -f2 -z | |
| #> llollo ;; See the stdin as two lines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Examples for (GNU) xargs | |
| # ==== -0, --null ==== | |
| echo -e "hello\0world" | gxargs -n1 | |
| #> gxargs: WARNING: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option? | |
| #> hello | |
| echo -e "hello\0world" | gxargs --null -n1 | |
| #> hello | |
| #> world | |
| #> ⏎ | |
| # ==== -a file, --arg-file=file ==== | |
| echo -e "hello\nworld" > /tmp/xargs; gxargs --arg-file=/tmp/xargs -n1 | |
| #> hello | |
| #> world | |
| # ==== --delimiter=delim, -d delim ==== | |
| echo -e "hello\nworld" | gxargs --delimiter=o -n1 | |
| #> hell | |
| #> ⏎ | |
| #> w | |
| #> rld | |
| #> ⏎ | |
| # ==== -E eof-str ==== | |
| echo -e "hello\nworld" | gxargs -E world -n1 | |
| #> hello | |
| # ==== -e[eof-str], --eof[=eof-str] ==== | |
| # Not recommended, use -E instead | |
| # ==== -I replace-str ==== | |
| echo -e "hello\nworld" | gxargs -I x -n1 echo x=x | |
| #> hello=hello | |
| #> world=world | |
| # ==== -i[replace-str], --replace[=replace-str] ==== | |
| echo -e "hello\nworld" | gxargs -i -n1 echo "{}={}" | |
| #> hello=hello | |
| #> world=world | |
| # ==== -L max-lines ==== | |
| echo -e "he\nllo\nwor\nld" | gxargs -L2 | |
| #> he llo | |
| #> wor ld | |
| # ==== -l[max-lines], --max-lines[=max-lines] ==== | |
| echo -e "hello\nworld" | gxargs | |
| #> hello world | |
| echo -e "hello\nworld" | gxargs -l | |
| #> hello | |
| #> world | |
| # ==== -n max-args, --max-args=max-args ==== | |
| echo -e "hello\nworld" | gxargs -l2 -n1 | |
| #> hello | |
| #> world | |
| echo -e "hello\nworld" | gxargs -n1 -l2 | |
| #> hello world | |
| # ==== -P max-procs, --max-procs=max-procs ==== | |
| echo -e "hello\nworld" | gxargs -i -n1 -P 2 sh -c "sleep 1;echo {}" | |
| #> world | |
| #> hello | |
| # ==== -p, --interactive ==== | |
| echo -e "hello\nworld" | gxargs -l -p | |
| #> echo hello ?...y | |
| #> hello | |
| #> echo world ?...y | |
| #> world | |
| # ==== --process-slot-var=name ==== | |
| echo -e "hello\nworld" | gxargs -n1 --process-slot-var=NUM -P2 sh -c 'echo [$NUM] $@' x | |
| #> [0] hello | |
| #> [1] world | |
| # ==== -r, --no-run-if-empty ==== | |
| echo -e "" | gxargs | |
| #> ⏎ | |
| echo -e "" | gxargs -r | |
| #> 🚫 | |
| # ==== -s max-chars, --max-chars=max-chars ==== | |
| echo -e "hello\nworld" | gxargs -l -s10 | |
| #> gxargs: argument line too long | |
| echo -e "hello\nworld" | gxargs -l -s11 | |
| #> hello | |
| #> world | |
| # ==== --show-limits ==== | |
| echo -e "hello\nworld" | gxargs -l -s11 --show-limits | |
| #> Your environment variables take up 1516 bytes | |
| #> POSIX upper limit on argument length (this system): 258580 | |
| #> POSIX smallest allowable upper limit on argument length (all systems): 4096 | |
| #> Maximum length of command we could actually use: 257064 | |
| #> Size of command buffer we are actually using: 11 | |
| #> Maximum parallelism (--max-procs must be no greater): 2147483647 | |
| #> hello | |
| #> world | |
| # ==== -t, --verbose ==== | |
| echo -e "hello\nworld" | gxargs -l -t | |
| #> echo hello | |
| #> hello | |
| #> echo world | |
| #> world | |
| # ==== -x, --exit ==== | |
| echo $status | |
| #> 0 | |
| echo -e "hello\nworld" | gxargs -n2 -s15 | |
| #> hello | |
| #> world | |
| echo $status | |
| #> 0 | |
| echo $status | |
| #> 0 | |
| echo -e "hello\nworld" | gxargs -n2 -s15 -x | |
| #> gxargs: argument list too long | |
| echo $status | |
| #> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment