Skip to content

Instantly share code, notes, and snippets.

@plasticbrain
Last active December 26, 2015 11:39
Show Gist options
  • Select an option

  • Save plasticbrain/7145317 to your computer and use it in GitHub Desktop.

Select an option

Save plasticbrain/7145317 to your computer and use it in GitHub Desktop.
Handy Linux Commands
Get just the IP of a hostname
  • dig +short A <hostname>
Find the 10 largest files on the disk
  • du -a / | sort -n -r | head -n 10
Find/Replace text in files
  • sed -i 's/old-word/new-word/g' *.txt
Copy a file/directory into multiple dirs at the same time
  • echo *.*/public_html/ | xargs -n 1 cp -R dir_to_copy/
Helpful CD commands
  • cd (with no directory) takes you to your home dir (ie: cd ~)
  • cd - (with a hyphen) takes you back to the last directory you cd'd to
Re-run the previous command as sudo
  • sudo !!
Rename the file extensions of all the files in a directory
  • rename 's/.html$/.php/' *.html
Tunnel Traffic Over SSH
  • ssh -ND 9999 user@server.com

Once you enter your password, nothing will happen. This is because the -N switch tells SSH to (N)ot open an interactive session TIPS: Use the -C switch to enable compression

Quickly share files via python's simplehttpserver
  • cd /dir/with/files/ && python -m SimpleHTTPServer 8000
Starting a command with a space will exclude the command from history
  • <space>command
Use Brace Expansion to quickly rename/copy files
  • cp /var/www/foo.php{,.bak}

Is the same as: cp /var/www/foo.php /var/www/foo.php.bak

Get the 10 most popular commands
  • history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
Convert MKV to MP4

Note: requires libav-tools (sudo apt-get install libav-tools)

  • avconv -i filename_in.mkv -codec copy filename_out.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment