Monday 17 October 2011

Top 10 Command Line Shortcuts


Terminal logoHere's the top 10 shortcuts I use on the command line. THese should speed up your productivity quite nicely. If you're using the Gnome Terminal on Ubuntu (possibly other distro's too) you might need to enable ALT+f and ALT+b in the preferences.

  • ESC + .
    Escape key and the period/full stop at the same time will insert the last argument from the previous command. For example if your previous command is:
    echo Hello World
    Then this shortcut will insert 'World' and the current point. However, if your previous command was
    echo "Hello World"
    Then it will insert '"Hello World"'. Note also that it is relative to your position in the history. So if you have run 10 commands and you go up through your history to the fifth one and use this, it will give you the last argument from the fourth command not the tenth.
  • CTRL+[right arrow] or ALT+f
    ALT and f together will move the cursor forward by one argument.
  • CTRL+[left arrow] or ALT+b
    ALT and b is the shortcut for moving the cursor back one argument.
  • ALT+d
    ALT and d will delete one argument forwards.
    For example using it at this point:
    echo Hello▊ World
    Would delete the word 'World'. The removed text will go into the kill ring. Note it will not remove quotes with it. If above Hello World was quoted. It would leave "Hello".
  • CRTL+w or ALT+backspace
    This deletes one argument backwards.
    So using the same example as above:
    echo Hello▊ World
    This would remove 'Hello'. Note that CTR+w does remove quotes (ALT+backspace doesn't), so if it were:
    echo "Hello▊ World"
    You'd be left with echo World" with one quote.
  • CRTL+ALT+-
    This is basically undo. So if you accidentally deleted a work or line hit this to get it back.
  • CRTL+k
    This removes from the cursor to the end of the line, and out it into the kill ring. The kill ring is basically the clipboard on the command line.
  • CRLT+y
    This 'yanks' whatever is in the kill ring (clipboard) into the current position.
  • CRTL+a
    Jump to the start of the line.
  • CRLT+e
    Jump to the end of the line.
All of these should work in Emacs too.

More command-line related posts: Top Command Line Tips: Apache Access Log and Top 5 Command Line Tip Posts