12 Command Line Keyboard Shortcuts for Mac OS X Terminal

Dec 19, 2006 - 20 Comments

Terminal in Mac OS X

The command line in Mac OS X can be a very powerful and fun tool, so it’s good to know how to maneuver around if you find yourself in it. By default, the Mac OS X Terminal uses the Bash shell, which is what these keyboard shortcuts are intended for.

So if you’re ready to get your feet wet, open up the Terminal and try these shortcuts out, they’re sure to make your command line life easier.

While the keystrokes will perform some incredibly useful tasks, the complexity isn’t too deep or crazy so you should be able to try all these out within a minute or two. Take a moment to do that, learn a bit more about the command line, and have fun.

12 Command Line Keyboard Shortcuts for Mac OS X

These will work in the Mac Terminal for any version of Mac OS X, that includes the default Terminal app and third party terminal applications like iTerm as well. Technically, these should work in Linux and other Bash shells too, but obviously we’re focusing on the Mac here.

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

terminal

If you have any other handy keyboard shortcuts or tricks for the command line, share them with us!

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

20 Comments

» Comments RSS Feed

  1. kishan kumar says:

    Wonder Article Great piece of Article !!

  2. Cody says:

    See also `stty -a’.

    You’ll find some of those listed above there too. stty is a very useful command though perhaps it’s obscure to most and usually it’s not useful but when it is it’s very useful.

    See stty(1) for more info (that means: section 1 of the man page so man stty).

  3. Drew says:

    Thanks :)

  4. George says:

    A minor correction..

    Ctrl + T swaps the two characters on either side of the cursor.

    It only swaps the last two characters before the cursor when at the end of the line.

  5. Oddbjorn says:

    ctrl + arrow keys for fast navigation in text

  6. bibek says:

    nice one frens

  7. Alex says:

    hey! how to delete (clear) the whole line? not after or before the cursor. but the whole

  8. Sterding says:

    $ bind -P | grep not -v

    abort can be found on “\C-g”, “\C-x\C-g”, “\e\C-g”.
    accept-line can be found on “\C-j”, “\C-m”.
    backward-char can be found on “\C-b”, “\eOD”, “\e[D”.
    backward-delete-char can be found on “\C-h”, “\C-?”.
    backward-kill-line can be found on “\C-x\C-?”.
    backward-kill-word can be found on “\e\C-h”, “\e\C-?”.
    backward-word can be found on “\e[1;5D”, “\e[5D”, “\eb”.
    beginning-of-history can be found on “\e”, “\e[6~”.
    end-of-line can be found on “\C-e”, “\eOF”, “\e[4~”, “\e[8~”, “\e[F”.
    exchange-point-and-mark can be found on “\C-x\C-x”.
    forward-char can be found on “\C-f”, “\eOC”, “\e[C”.
    forward-search-history can be found on “\C-s”.
    forward-word can be found on “\e[1;5C”, “\e[5C”, “\ef”.
    glob-complete-word can be found on “\eg”.
    glob-expand-word can be found on “\C-x*”.
    glob-list-expansions can be found on “\C-xg”.
    history-expand-line can be found on “\e^”.
    insert-comment can be found on “\e#”.
    insert-completions can be found on “\e*”.
    insert-last-argument can be found on “\e.”, “\e_”.
    kill-line can be found on “\C-k”.
    kill-word can be found on “\ed”.
    next-history can be found on “\C-n”, “\eOB”, “\e[B”.
    non-incremental-forward-search-history can be found on “\en”.
    non-incremental-reverse-search-history can be found on “\ep”.
    operate-and-get-next can be found on “\C-o”.
    possible-command-completions can be found on “\C-x!”.
    possible-completions can be found on “\e=”, “\e?”.
    possible-filename-completions can be found on “\C-x/”.
    possible-hostname-completions can be found on “\C-x@”.
    possible-username-completions can be found on “\C-x~”.
    possible-variable-completions can be found on “\C-x$”.
    previous-history can be found on “\C-p”, “\eOA”, “\e[A”.
    quoted-insert can be found on “\C-q”, “\C-v”, “\e[2~”.
    re-read-init-file can be found on “\C-x\C-r”.
    reverse-search-history can be found on “\C-r”.
    revert-line can be found on “\e\C-r”, “\er”.
    self-insert can be found on ” “, “!”, “\””, “#”, “$”, …
    set-mark can be found on “\C-@”, “\e “.
    shell-expand-line can be found on “\e\C-e”.
    start-kbd-macro can be found on “\C-x(“.
    tilde-expand can be found on “\e&”.
    transpose-chars can be found on “\C-t”.
    transpose-words can be found on “\et”.
    undo can be found on “\C-x\C-u”, “\C-_”.
    unix-line-discard can be found on “\C-u”.
    unix-word-rubout can be found on “\C-w”.
    upcase-word can be found on “\eu”.
    yank can be found on “\C-y”.
    yank-last-arg can be found on “\e.”, “\e_”.
    yank-nth-arg can be found on “\e\C-y”.
    yank-pop can be found on “\ey”.

  9. Ivan Storck says:

    A useful tip to see all keyboard shortcuts is:

    %> bind -P

    so to delete the word after the curso, use esc-d ( \ed )

  10. Ajay Goel says:

    Is there any key to delete the word after the cursor, like CTRL + W before the cursor?

  11. Ajay Goel says:

    Is there any key to delete the word after the cursor, like CTRL + W before the cursor?

  12. Tim Harper says:

    Is there any way to change the binding to the delete previous word? I find ctrl-w a difficult reach, and I prefer the apple-backspace.

    Thanks!

  13. anon says:

    For those who find this site, you can set the behavior of bash by using:

    set -o vi

    for vi command editing mode. It defaults in emacs mode (the keybindings above).

    vi mode starts in editing mode, but pressing esc and you’re back into the glorious world of vi.

    if you want to retain ctrl+L clear screen behavior in vi mode, try adding this to your .bashrc (or equivalent) file:

    bind -m vi-insert “\C-l”:clear-screen

    (thanks to http://www.jukie.net/~bart/blog/20040326082602)

  14. clcl says:

    Cool — I love the Ctrl + L thing as a substitute for clear — because now I can clear the screen, arrow-up for history of my last commands — without having to skip the clear command itself. Sounds trivial, but that was annoying me! Thanks!

  15. mrumrici says:

    Aaweosmeom!!!

  16. FJ says:

    Love the list, watch out for spammers!

  17. soho says:

    Very nice – thanks alot for this list

  18. anonymous says:

    Are you kidding me – I’ve been using Bash for 5 freaking years and I never knew any of this. Thanks!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site