Ctrl + A Go to the beginning of the line you are currently typing on Ctrl + E Go to the end of the line you are currently typing on Ctrl + L Clears the Screen, similar to the clear command Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. Ctrl + H Same as backspace Ctrl + R Let's you search through previously used commands Ctrl + C Kill whatever you are running Ctrl + D Exit the current shell Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it. Ctrl + W Delete the word before the cursor Ctrl + K Clear the line after the cursor Ctrl + T Swap the last two characters before the cursor Esc + T Swap the last two words before the cursor Alt + F Move cursor forward one word on the current line Alt + B Move cursor backward one word on the current line Tab Auto-complete files and folder names
Contents
|
!! (Full contents of previous command)
How many times have you tried to edit a file, then realize that you need to be root to do it? Use bang-bang to quickly repeat the previous command, with other commands before or after.
vi /etc/init.d/mongrel_cluster => Permission Denied sudo !! => Now opens the file as root
!$ (Last arg of previous command)
Sometimes I need to reuse the last argument with another command, like here where I forgot to quote a string.
wget http://weather.yahooapis.com/forecastrss?p=98117 => wget: No Match wget '!$' => Now it works
Sets
{a,b} (A set)
How often do you rename just part of a file? The {} syntax is convenient.
mv file.{txt,xml} => Expands to 'mv file.txt file.xml'
mv file{,.orig} => Expands to 'mv file file.orig'
mkdir foo{1,2,3} => Expands to 'mkdir foo1 foo2 foo3'
OSX specific
pbcopy and pbpaste
In Mac OS X, you can copy things to the clipboard and read them back out. This is nice because you can reuse it in the shell or back in the OS with Apple-C or Apple-V.
./generate_random_password | pbcopy pbpaste > file.txt