Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Disclaimer & Notes

I am not the author of this content. I simply, or not so simply, pulled out the commands and paraphr​ ased from the discuss​ ions of the authors of Command Line Kung Fu. Every episode should be linked. In some cases, I may have updated their commands if I noticed they were outdated. I plan on continuing to add all episodes. Let me know what my errors are. C:\> Windows C:\> Windows Powershell # $ OS X

Episodes #1-10

Episode # dos2unix .txt #1 Convert # 's/\r$//' file.txt >newfile.txt Dos To UNIX

Episode C:\> netsh firewall show portope​ ning C:\> netsh firewall show allowedprogram #2 show all ports allowed show all programs allowed Looking C:\> netsh firewall show config # for in nat mangle filter raw; do iptables -t $type -; done the show all config options list all iptables rules in all chains Config of Built-In Firewall

Episode C:\> for /L %i in (1,0,2) do @dir /b /a | /c /v ""​ & ping -n 6 127.0.0.1>​ nul #3 Watching # -n 5 ' | -l' the File Count in a Directo​ ry

Episode C:\> for /r c:\ %i in (*) do @ %~zi, %i #4 output to csv and in spreadsheet

Listing # | sort -nr | -100 # find / -type f -exec wc -c {} \; | sort -nr | head -100 show 100 largest files in descending order Files and show top 100 largest directories in descending order Their Sizes

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 1 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode #5 C:\> FOR /F "t​ oke​ ns=​ 1-5​ " %a in (lookup​ s.txt) do @(@FOR /F "t​ oke​ ns=1-4 delims=​ ." %i in Simple Text Manipul​ ation - ("%a"​ ) do @echo %l.%k.%j​ .%i %e) Reverse DNS Records # sed 's/\([0​ -9]​ *\​ )\.\([​ 0-9​ ]*​ \)\​ .\​ ([0-​ 9]*​ \​ )\.\​ ([0​ -9]​ *\​ ).in​ -a​ ddr​ .arpa domain name pointer​ \(.*\​ )\./\​ 4.\​ 3.\​ 2.\​ 1\5/' lookups​ .txt lookups.txt format: 208.251​ .16​ .10​ .in​ -ad​ dr.arpa domain name pointer server2​ .sr​ v.my​ do​ mai​ n.ne​ t.

Episode #6 C:\> FOR /L %i in (1,1,255) do @ping -n 1 - 100 10.10.10​ .%i | find "R​ epl​ y" Command​ -Line Ping Sweeper # for i in `seq 1 255`; do ping -c 1 -w 1 10.10.10​ .$i | \\n ' ' | '/1 received/ {print $2}'; done

Episode #7 C:\> /a C:\> shutdown /r /t Aborting a System Shutdown abort shutdow​ n [#_seco​ nds]

# shutdown -c to try delaying shutdow​ n # shutdown -r hh:mm:ss reboot at hh:mm.ss (24 hr clock) cancel scheduled # shutdown -r +<#>​ shutdow​ n reboot in # minute(​ s)

Episode #8 C:\> -s C:\> netstat -s -p tcp Netstat Protocol Stats all protoco​ ls all tcp # netstat -s # netstat -s | awk '/:/ { p = $1 }; (p ~ /^[Tt]​ /) { print }' all protoco​ ls all tcp (works for OS X too)

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 2 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode #9 C:\> find /v /n ""​ | findstr /b /L [<#>​ ] C:\> for /F "delims=[] tokens=2" %i in (tmp.txt) do @echo %i & del tmp.txt Display the will prepend line numbers to output used to remove line numbers in output (save output of previous cmd to temp.txt) Nth Line # awk 'FNR = <#>' # head -<#> | -1 alternative command

Episode C:\> findstr /s /d:

s /m *. C:\> findstr /s /m *​ #10 dir=absolute|relative, filetype=file extension alternative format Display # find -type f -exec -l {} + # find -type f -print0 | xargs -0 grep -l Filenames flexible, allows for multiple -exec predicates alternative safer command (except on Solaris =P) Containing # grep -irl Additional Research Links String slow for larger searches, easy to remember xargs vs exec uses & xargs vs exec efficiency Within the File

Episode C:\> dir /tc / #11 oldest first (/o-d will show newest first) Listing # ls -li | sort -n Files by rela​ tive times from clustered inodes Inode as a Proxy for Create

Episode PS C:\> sls [email protected] -list -path qf* | -path {$_.Path -replace "\\qf","\[qd]f"} #12 Note, this is PowerShell Deleting C:\> cmd.exe /v:on /c "for /f %i in ('findstr /m [email protected] qf*') do @set stuff=%i & del qf!stuff:~2! & del !stuff:~2!" Related # grep -l [email protected] qf* | -c3- | xargs -I {} rm qf{} df{} Files

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 3 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode #13 DEPRE​CATED Nessus format, no longer necessary Find C:\> for /F "d​ eli​ ms=:| tokens=​ 2" %i in ('findstr CVE-200​ 8-4250 *.nsr') do @echo %i Vulnerable # awk -F'|' '/CVE-2​ 008​ -4250/ {print $1}' | sort -u Systems In A funnel those IP addresses through to Metaspl​ oit's msfcli and get shell on all of them Nessus Export

Episode #14 C:\> doskey / C:\> F7 Command up to 50 commands stored by default bring up prompt with history Line (History) # CTRL+r # CTRL+p | CTRL+n Shortcu​ ts find & run cmd containing string (ENTER | CTRL+g) previous or next command in history (up & down) # !:p # ! only display cmd, then !! to run run last cmd that starts with string # !! # !-<#> run previous cmd run # previous cmd # !$ # !-<#>$ run a cmd with last argument of prev cmd (ALT+. also works) run a cmd with last argument of # prev cmd # !* # !-<#>* run a cmd with all arguments of prev cmd run a cmd with all arguments of # prev cmd # ^foo^bar # !:gs/foo/bar/ run prev cmd replacing 1st instance of foo with bar run prev cmd replacing all instances of foo with bar # ^ run prev cmd removing 1st instance of string

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 4 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode C:\> net user C:\> dir /tc "C:\Documents and Settings\" C:\> dir #15.1 last time password was set first logged in (before Vista) /tc New #awk -F: '/^:/ {print $3 * 86400}' /etc/shadow # ls -ltd /home//.[^.]* | tail -1 C:\Users\ User last time password was set (Epoch time) first logged in first Created logged in

When? (Vista+​ )

Episode C:\> cscript c:\windows\system32\eventquery.vbs /L security /FI "id eq 642" #15.2 using “audit account management” event log (XP & 03) New C:\> wevtutil qe security /f:text "/q:*[System[(EventID=4720)]]" | more User using “audit account management” event log (Vista+) Created # grep /var/log/secure* | tail When? limited history (may be in /var/log/auth.log) Cont.

Episode C:\> wmic qfe where hotfixi​ d="​ K​ B95​ 864​ 4" list full # rpm -qa --qf "%​ -30​ {NAME} %-15{VE​ RSION} % #16 whether MS08-067 was installed and when {INSTA​ LLT​ IME​ :da​ te}​ \n"​ Got # apt-sho​ w-v​ ers​ ions -u RHEL report for all package​ s That Debian based (/var/c​ ach​ e/a​ pt/​ arc​ hives may have install $ ls -l com.app​ le.pkg​ .up​ dat​ e.* Patch? dates) OS X packages and timesta​ mps

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 5 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode C:\> for /F %i in (names.txt) do @echo %i & -norecurse %i [DNSserver] | find "answer" & echo. #17 names.txt contains names to check, DNSserver is optional chosen DNS server DNS # for i in ` names.txt`; do -r $i [nameserver]; done Cache names.txt contains names to check, DNSserver is optional chosen DNS server Snooping # rndc dumpdb -cache in a Single if you are the server Command # -a -c named -d cwd find the current working directory of the named process

Episode C:\> ipconfig /flushdns C:\> ipconfig /displa​ ydns #18 # nscd -i hosts # netstat -rCn Clearing linux flush linux recent communi​ cat​ ion The $ dscache​ util -flushc​ ache $ dscache​ util -cachedump -entries Host System OS X flush OS X display cache DNS Lookup Cache

Episode C:\> type nul > my_file C:\> copy nul my_file #19 shorter command Clearing # cat /dev/null > my_file # cp /dev/null my_file The shorter command Contents Of A File

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 6 of 7. https://readability-score.com Command Line Kung Fu Commands Cheat Sheet by karaliking via cheatography.com/25231/cs/6623/

Episodes #1-10 (cont)

Episode #20 C:\> for /L %i in (1,0,2) do @(ping -n 1 HostIPaddr > nul || echo ^G) & ping -n 2 127.0.0.1 > nul Ping Beep of not ^ and G, actually CTRL+g Death # ping x.x.x.x 2>&1 | awk -F: '/sendto:/ {print $3}' | say $ ping -A 192.168​ .1.1

By karaliking Published 2nd February, 2016. Sponsored by Readability-Score.com cheatography.com/karaliking/ Last updated 24th April, 2016. Measure your website readability! Page 7 of 7. https://readability-score.com