I came across a very useful post with the listing of many shell keyboard shortcuts. The article covers a mix of bash, csh, zsh, and Cisco shell keyboard shortcuts. The article is in Russian, but I think it will be helpful for more people, so I took the liberty to translate it. Continue reading for the translation.
In this article I will show some keyboard shortcuts, which can make life easier for administrators who work in the command line. All of these shortcuts work in bash. I’ve also tried all of them in Cisco shell (Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVCESK9_WAN-M), Version 12.2(33)SXH4), csh and zsh. I will try to avoid duplicating content from other articles. All shortcuts are grouped by the functional key. This article should be particularly useful to those people who are used to Home, End, and Delete keys (which are “not working” in Cisco shell).
A few shortcuts with the Ctrl key.
Ctrl + a – jump to the beginning of line (Cisco, csh, zsh)
Ctrl + b – move one character backwards (Cisco, csh, zsh)
Ctrl + c – send SIGINT signal to the current job. Usually interrupts the running task (csh, zsh)
Ctrl + d – delete character at cursor position (exactly like Delete key) (Cisco, csh, zsh)
Ctrl + e – jump to the end of line (Cisco, csh, zsh)
Ctrl + f – move one character forward (Cisco, csh, zsh)
Ctrl + k – delete everything to the end of line (EOL, not the screen edge) (Cisco, csh, zsh)
Ctrl + l – clear screen (exactly like clear command) (csh, zsh)
Ctrl + r – search through history. Repeated search (search results listing). Incremental search. (zsh)
Ctrl + j – stop search and allow to edit found command. If there was no prior search, then behave exactly like Enter key (in zsh runs the command)
Ctrl + t – change character at cursor position to the one before. Or move previous character towards the end of line, if you will. (Cisco, csh, zsh)
Ctrl + u – delete all characters from position to the left of the cursor to the end of line (Cisco, in csh and zsh deletes the whole line)
Ctrl + w – delete all characters from position to the left of the cursor to the beginning of the word (Cisco, csh, zsh)
Ctrl + xx – jump between current cursor position to the beginning of the line and back. In Cisco works exactly like Ctrl + u (csh)
Ctrl + x @ – shows hostname completion matches (hostnames are taken from /etc/hosts)
Ctrl + z – suspend current task (csh, zsh)
Ctrl +x ; Ctrl + e – open $EDITOR for editing of the current command line. After changes are saved, the command is executed.
Now a few shortcuts with the Alt key
Alt + < – jump to the first command in history (zsh)
Alt + > – jump to the last command in history
Alt + ? – shows possible matches for the command completion (similar to Tab – Tab) (in csh, zsh works exactly like which string)
Alt + * – inserts all possible completion matches into the command line
Alt + / – attempts to complete the filename (similar to Tab)
Alt + . – inserts the last parameter of the previous command (like !$, but you don’t need to do :p to check)
Alt + b – moves the cursor backwards by one word (Cisco, csh, zsh)
Alt + c – converts character under the cursor to upper case, and the rest of the characters in the word to lowercase (Cisco, csh, zsh)
Alt + d – deletes characters from current cursor position to the end of the word (Cisco, csh, zsh)
Alt + f – moves cursor forwards by one word (Cisco, csh, zsh)
Alt + l – converts all characters from current position to the end of the word to lower case (Cisco, csh, zsh)
Alt + t – swaps the word at cursor position with the next one (zsh)
Alt + u – convers all characters from current position to the end of the word to upper case (Cisco, csh, zsh)
Alt + Backspace – deletes characters from current cursor position to the beginning of the word (Cisco, csh, zsh)
In the next listing, I will use “2T” for a double tabulation (Tab-Tab).
2T – command completion. If done on an empty line, will show the listing of all possible commands
(string)2T – list completion matches
(dir)2T – list subdirectories of dir
*2T – list subdirectories, omitting hidden ones (those that start with a .)
~2T – list users from /etc/passwd. You can go directly to user’s home directory after the username completion.
$2T – list all environment and system variables
@2T – list hostname completion matches, using /etc/hosts
I am mostly working with bash and Cisco shell, so I wrote down those shortcuts that I know work in other shells. I’m sure csh and zsh have as much features as bash, but I am not too familiar with them. The above list of shortcuts needs a notice: all these shortcuts can be re-assigned in bash. There are some actions which are not assigned to shortcuts by default. Similar “tricks” are described in the bash manual, which I strongly recommend for reading.