This post is part of a series of tutorials on OS X command line. Please read the following first to get started:
We continue our exploration of OS X command line by highlighting editing keyboard shortcuts in the Terminal app. These keyboard shortcuts described are the default editing settings for a terminal running bash shell under OS X. Many of the keyboard shortcuts will also work in standard text field you encountered in any Mac app.
- Right Arrow or Control-F to move the cursor forward one character
- Left Arrow or Control-B to move the cursor backward one character
- Delete key or Control-H to delete one character
- Control-D to forward delete one character
- Control-A to move the cursor to the beginning of line
- Control-E to move the cursor to the end of line
- Control-K to delete everything from under the cursor to the end of line
- Control-U to delete everything from under the cursor to the beginning of line
- Control-W to delete from under the cursor to the beginning of the word
- Esc-F to move forward one word
- Esc-B to move backward one word
- Control-R to recall previous command by searching through command history
- Control-T to transpose (swap) with one another the two characters before the cursor
- Esc-T to transpose (swap) with one another the two words before the cursor
- Up Arrow or Control-P to go back previous commands in history
- Down Arrow to forward previous commands in history. It is the reverse of Up Arrow/Control-P.
- Tab to auto-complete name of file, folder or program
- Control-L or Command-K to clear the screen
The above is not an exhaustive list of all editing shortcuts and capabilities, but is sufficient as a starting point to get you productive on the command line.