Useful command line keyboard shortcuts

I use these bash keyboard shortcuts every day and they save me plenty of time, so I find them worth sharing. Even if you’re developing on Windows, you can have (similar) experience of the Linux bash using the Cygwin tool.

CTRL + R, then arrow up/down
Search in the history of bash commands. Press CTRL + R, type a couple of letters, and the most recent matching command jumps out of history. Press CTRL + R again, and you get older result matching your search string. Once you find your command, you hit either Enter to execute the command directly from reverse search, or any other key to keep it in the command line and be able to edit it (I usually use ESC or right/left arrow or the End key). I use this all the time to recall my previous mysql and ssh commands, or other ones which are too long to type. You can use any keyword inside the command when searching.

Arrow Up / Down
Load previous / next commands from the bash history.

TAB
Autocomplete for commands or filenames. Type first letter(s) and hit TAB. If there are multiple choices matching your first letters, hit TAB again to see the list of them.

CTRL + Arrow Left / Right
Move the cursor word-after-word in the command line. On Mac OS X: ALT + Arrow Left / Right, or ESC + B and ESC + F.

HOME or CTRL + A
Move cursor to the beginning of the line. Only CTRL + A on Mac OS.

END or CTRL + E
Move cursor to the end of the line. Only CTRL + E on Mac OS.

CTRL + K
Delete everything after the cursor (right to the cursor).

CTRL + U
Delete everything before the cursor (left from the cursor).

CTRL + W
Delete only 1 word immediately before the cursor.

CTRL + Y
Undo a deletion, sometimes useful.

CTRL + L
Clear screen, works like the “clear” command.

CTRL + C
Kill the current process.

CTRL + D
Pressed on an empty line: log out from the current terminal. Works pretty much the same as the “exit” command.

Do you have any other favorites which are not mentioned here? Feel free to share them in the comments.

Leave a Reply

Your email address will not be published.