Advertisement
thioshp

CommandLineFu Random Tips

Mar 13th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.54 KB | None | 0 0
  1. # vim: ft=markdown
  2.  
  3. # Read randomly generated CLI tips wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed -n '1d; /./p'
  4.  
  5. # get all bookmarks from all profiles from firefox
  6. `"SELECT strftime('%d.%m.%Y %H:%M:%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;";  done`
  7. # Encrypt your file using RC4 encryption
  8. `hashkey=`echo -ne <your-secret> | xxd -p`; openssl rc4 -e -nosalt -nopad -K $hashkey -in myfile.txt -out myfile.enc.txt`
  9. # Block an IP address from connecting to a server
  10. `iptables -A INPUT -s 222.35.138.25/32 -j DROP`
  11. # View details of network activity, malicious or otherwise within a port range.
  12. `lsof -i :555-7000`
  13. # Rename files in batch
  14. `rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*`
  15. # oneliner to transfer a directory using ssh and tar
  16. `tar cvzf - dir | ssh my_server 'tar xzf -'`
  17. # Mac OS X (laptops ??) only :  control hibernation state more easily from Terminal.app
  18. `sudo pmset -a hibernatemode 1`
  19. # Inverted cowsay
  20. `echo Which way up? | flip.pl | cowsay | tac | sed -e "s,/,+,g" -e "s,\\\,/,g" -e "s,+,\\\,g" -e "s,_,-,g" -e "s,\^,v,g"`
  21. # Compare directories (using cmp to compare files byte by byte) to find files of the same name that differ
  22. ```bash
  23. find . -maxdepth 1 -mindepth 1 -print0 | xargs -0 -n 1 -I % cmp % /DUPDIR/% 2>/dev/null
  24. ```
  25. # Downloads files (through wget) from a list of URLs using a stored cookie
  26. `wget --load-cookies <cookie-file> -c -i <list-of-urls>`
  27. # Adding Prefix to File name
  28. `rename 's/^/CS749__/' *.pdf`
  29. # Merge only certain pdfs in a directory
  30. `gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged.pdf -dBATCH `ls | grep foo``
  31. # Use md5 to generate a pretty hard to crack password
  32. `echo "A great password" | md5sum`
  33. # list files recursively by size
  34. `stat -c'%s %n' **/* | sort -n`
  35. # Show amicable path
  36. `alias path='echo $PATH | tr ":" "\n"'`
  37. # Tool for generating system resource statistic
  38. `dstat`
  39. # Create a tar of directory structure only
  40. `tar -cf ~/out.tar --no-recursion --files-from <(find . -type d)`
  41. # Debug pytest failures in the terminal
  42. `pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no`
  43. # Extract raw URLs from a file
  44. `egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep ://`
  45. # Display the top ten running processes - sorted by memory usage
  46. top -b -o +%MEM |head -17
  47. # Snmpwalk a hosts's entire OID tree with SNMP V3 with SHA Authentication and with Privacy
  48. snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> .
  49. # Human readable docker stats output
  50. docker stats --no-stream $( docker ps -q ) | sed -e "$( docker ps --format "{{.ID}} {{.Names}}" | sed -e "s/\(.*\) \(.*\)/s\/\1\/\2\t\/g;/" )"
  51. # Realtime delay effect
  52. arecord -D plughw:1,0 | play -d echos 0.3 0.2 700 0.25 800 0.3
  53. # Rename files in batch
  54. rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*
  55. # list size and directies in curretn folder
  56. du -sh ./*/
  57. # PulseAudio: set the volume via command line
  58. pactl set-sink-mute 0 false ; pactl set-sink-volume 0 +5%
  59. # Android PNG screenshot
  60. adb exec-out screencap -p > screenshot.png
  61. # Find a CommandlineFu users average command rating
  62. curl -s www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/num-votes/{S+=$2; I++}END{print S/I}'
  63. # transpose a file
  64. awk '{ for (f = 1; f <= NF; f++)   a[NR, f] = $f  }  NF > nf { nf = NF } END {   for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++)     printf a[r, f] (r==NR ? RS : FS)  }'
  65. # list all directory sizes and sort by size
  66. du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement