BASh Shortcuts
I’ve been using Linux for nearly a decade. Typically, that means an Ubuntu server with a Bash shell. During this time, more than a handful of Bash shortcuts have presented themselves to me. Therefore, I thought it prudent to keep a running list, as much for my own benefit as that of anyone else.
What is a shell?
Most Unix systems provide the same basic utilities for working at the shell prompt. The syntax used for writing shell commands is standardized. By this, I mean re-directions, pipes, background processes, variables assignments, quoting, and so on. The standard is called POSIX, which I believe was first standardized 32 years ago by the IEEE. The current edition is here: http://pubs.opengroup.org/onlinepubs/9699919799/ (see the “Shell & Utilities” section, there doesn’t seem to be a great way to link directly to it).
On most Unix systems, the POSIX standard is at least observed, but may oftentimes be extended. In particular, the shell itself is often extended to give a more convenient interactive experience, or to be able to provide more advanced shell programming facilities.
Just as you might find many different shells on the beach, you’ll find many different shells to work in. After all, they are “just” applications. bash
is the default on Debian / Ubuntu, (and I also believe MacOS), which makes it the hands down winner in my book. Curious what shell code looks like? Here’s the bash
git repository page: https://git.savannah.gnu.org/cgit/bash.git
The shortcuts below are quite helpful in my day to day, but I can’t confirm that they work on other shells (such as, zsh
or ksh
). In addition, it is doubtful that this list is complete. However, I will do my best to keep it up to date with my discoveries.
Cursor Control Shortcuts in Bash
CTRL+A
orHome
– Move the cursor to the start of the lineCTRL+E
orEnd
– Move to the end of the lineCTRL+B
orLeft Arrow
– Move back one characterCTRL+F
orRight Arrow
– Move forward one characterCTRL+Left Arrow
orALT+B
orEsc
and thenB
– Move back one word at a timeCTRL+Right Arrow
orALT+C
orEsc
and thenF
– Move forward one word at a time
Screen Controls Shortcuts in Bash
CTRL+L
or typeclear
– Clean up the screenCTRL+S
– Pause the screen. Useful if the screen is scrolling long outputCTRL+Q
– Resume the screen after a pause (CTRL+S
)
Search Bash History
CTRL+P
orUp Arrow
– Recall previous command (cycle through CLI history)CTRL+N
orDown Arrow
– Move to a more recent command (reverse cycle through CLI history)CTRL+R
– Reverse search. After starting a reverse search, type the characters unique to your commandCTRL+S
– Forward search through bash historyCTRL+G
– Quit the reverse or forward search
Delete Text in Bash
Backspace
– Delete text behind the cursorCTRL+X
thenBackspace
– Delete ALL text behind the cursorCTRL+K
– Remove all text from the cursor to the END of the line
Managing Linux Processes
CTRL+Z
– Suspend the current process that is running in the foreground. This key combination produces a SIGTSTP signal to the process.Type
fg
– Brings a process back to the foreground (after suspending it withCTRL+Z
)CTRL+C
– Interrupt the current process.CTRL+\
– Produces a SIGQUIT signal, and causes the current process to terminate and core dump. This is especially useful whenCTRL+C
is unresponsive.
Bang Commands
!!
– Execute last command!pyth
– Execute the most recent command that starts withpyth
!pyth:p
– Display the command that!top
would run, and places it at the top of the history!$
– Execute the last word of the last command. For example, if you typed,vim slippySalamander.py
then issuingpython3 !$
will attempt to executeslippySalamander.py
with Python.!$:p
– Display the word that!$
would execute!*
– Display the last word of the previous command!:*p
– Display the last word that!*
would substitute
Getting Bash help
To find any kind of general help with Bash issue man bash
Links & References
GNU Bash Reference – Bash Reference Manual
Setting a Vim Color Scheme – https://rzfeeser.com/2020/02/04/setting-a-vim-color-scheme/