Bash: Command Line Shortcuts

Here's a few shortcuts that may increase your productivity in the command line.

Navigate around the current command

ctrl+a -- Go to the beginning of the line.
ctrl+e -- Go to the end of the line.
ctrl+w -- Delete last word.
ctrl+k -- Delete everything after the cursor.
esc+f -- Move cursor forward one word.
esc+b -- Move cursor back one word.

Recall the last command with !!

Sure you can press the up arrow to recall the last command, but let's say you want to add "sudo" at the beginning. Instead of pressing up arrow, navigating to the beginning of the command, then adding "sudo ", you can simply do this:

$ ./ ./ Permission denied$ sudo !!sudo ./$ 

This is a pretty small command, but you can imagine how it might make life a little easier if it were a command with lots of arguments.

Recall the last arguments with !$

!$ is a shortcut for all the arguments from the last command.

$ mkdir /home/me/work/foo$ cd !$cd /home/me/work/foo$ 

You can also recall a specific argument with !:

$ cp foo /some/long/path/to/where/foo/should/go$ cd !:2$ pwd/some/long/path/to/where/foo/should/go$

For more fun stuff with bash, check out the manual.
$ man bash