This is just a collection of useful commands that were new to me at one point. Most of them have been assimilated into my normal workflow.

General

search in this and all subdirectories for a given string
grep -r “search_string” .
find / | grep <search_string>

tar
tar -czvf <archive.tgz> <files/directory>
tar -zxvf <archive>

display size of
du -sh <path>

shoveling bits
dd if=<file-to-write> of=<output-path> bs=<block-size>
dd if=~/stuff/awesome-image.img of=/dev/sdc bs=1M

manipulate System-V init scripts
update-rc.d [-f] <service> remove
update-rc.d <service> defaults

Internet

transfer (sync) files with rsync
rsync -avhP username@host:<src> <dst>
(options) -archive verbose human-readable Progress

download a working copy of a website with wget
wget -mkpEH --wait=20 --random-wait <site> [--no-parent]

options:

-m = --mirror = turn on options suitable for mirroring [downloaded content]  
-k = --convert-links = make links suitable for local viewing  
-p = --page-requisites = download all files to display a web page (css, images, etc.)  
-E = --adjust-extension = change filename of html served over cgi, asp, etc. to end with .html  
-H = --span-hosts = allow retrieving dependencies from different hosts  
--no-parent = don't go above specified directory in file hierarchy  
-U = set user agent string  

Git

Change the commit message for last commit
git commit --amend
Store changes and restore local to last clean state
git stash save “stash_message”
Playback stash onto current state
git stash pop
Pull changes in all submodules
git submodule foreach git pull origin master

Vim

Save all open buffers
:wa

ctrl-u Move screen up ½ page
ctrl-d Move screen down ½ page

zz move current line to the middle of the screen
zt move current line to the top of the screen
zb move current line to the bottom of the screen

ctrl-a Increment number under cursor
ctrl-x Decrement number under cursor

Macros
q<lowercase_letter> start macro recording in specified register
...commands...
q stop macro recording
@<register> play back recording
n@<register> repeat macro n times

Gnome (3)

Set secondary monitor to switch with workspaces
gsettings set org.gnome.shell.overrides workspaces-only-on-primary false

Less than helpful commands

Fork Bomb
$ :(){ :|:& };:

kmem Russian Roulette
dd if=/dev/urandom of=/dev/kmem bs=1 count=1 seek=$RANDOM

Tags: linux, git, vim