int0x76

cmd line tips

Aug 12th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. Command line
  2. ------------
  3. # Get the first argument of the previous command. This is a readline thing.
  4. [Ctrl]+[Alt]+Y
  5.  
  6.  
  7. File
  8. -----
  9. Count the number of commas (,) in a text file: .tr -cd , < file.txt | wc -m #
  10. grep -n "search term" -r . | cut -d ":" -f 1 # extract the paths of a grep output and use them further...
  11. find . -name '*.pdf' -exec pdftotext {} - \; | grep "search term" # grep multiple pdf files
  12. file .* * # List all files in the current directory, and describe their contents.
  13.  
  14. mkdir ". " && cd ". " && touch FILE # put as many spaces as you want after dot. Hiding files in Linux
  15.  
  16. Encryption
  17. ----------
  18. echo "Uryyb jbeyq" | tr '[A-Za-z]' '[N-ZA-Mn-za-m]' # Perform ROT13 on a string.
  19.  
  20.  
  21.  
  22.  
  23. Password
  24. --------
  25. dd if=/dev/random bs=16 count=1 2>/dev/null | base64 | sed 's/=//g' # Generate a secure password with 128 bits of entropy.
  26.  
  27.  
  28. Edit file
  29. ---------
  30. sed '/^\#/d' in_file > out_file # get rid of lines starting with # (aka comments)
  31.  
  32.  
  33. Networking
  34. ----------
  35. tar -cz folder | ssh username@destinationhostname "cat >output.tgz" | Archive 'folder' onto a different computer.
  36.  
  37. Web
  38. ---
  39.  
  40.  
  41. Curl
  42. ----
  43. # see where a URL shortener points
  44. curl -s -D - -o /dev/null http://bit.ly/frXy3V | grep -i ^location:
  45. curl -s "http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1 …" # View current stock price for AAPL
  46. curl -LIN "$URL" # See HTTP response headers and any redirects for $URL
  47.  
  48.  
  49. Wget
  50. ----
  51. wget -O /dev/null http://speedtest.wdc01.softlayer\.com/downloads/test10.zip # Check broadband speed
  52. wget -r -l 1 -A pdf ftp://ftpserver/pub/documents/ # download all .pdf files from an ftp server
  53.  
  54.  
  55.  
  56. Desktop
  57. -------
  58. # site shot from command line. By
  59. xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=http://url --out=image.png
  60.  
  61.  
  62.  
  63. Networking
  64. ----------
  65. # Show the network calls of the ping command.
  66. strace -s 200 -e trace=network -f ping -c1 4.2.2.2
  67.  
  68. # route port 80 to default or custom port
  69. ltunnel(){ port=3000; sudo ssh -L 80:localhost:${1-$port} $(whoami)@localhost }
  70.  
  71.  
  72. Netcat
  73. ------
  74. nc -z example\.com 22 # Check if port 22 is listening on http://example.com
  75.  
  76.  
  77. Logfiles
  78. --------
  79.  
  80. tail error_log continuously and add extra newline. May help with readability when lines are long.
  81. tail -f error_log |awk '{print $0 "\n"}'
  82.  
  83. # sort and rank who is using sudo
  84. egrep -o "sudo:\s+\S+\s+:" /var/log/secure | sort | uniq -c | sort -g
  85.  
  86.  
  87. OpenSSL
  88. -------
  89. openssl enc -aes-256-cbc -salt -in yourfile -out yourfile.enc # Encrypt yourfile with a password without the need for gpg.
  90.  
  91.  
  92. Apache
  93. -------
  94. # Only view the active configuration in a heavily commented httpd.conf file.
  95. egrep -v "(^#|^\ *$)" httpd.conf | less
Advertisement
Add Comment
Please, Sign In to add comment