- What are the keyboard shortcuts for the command-line?
- Useful Linux Command Line Bash Shortcuts You Should Know
- Launch an Editor
- Controlling The Screen
- Move Cursor on The Command Line
- Search Through Bash History
- Delete Text on the Command Line
- Transpose Text or Change Case on the Command Line
- Working With Processes in Linux
- Bash Bang (!) Commands
- Common Linux command line shortcut keys
- First, mobile class
- Second, editing class
- Third, control class
- Iv. History
- 5 ways to navigate the Linux terminal faster
- Great Linux resources
- 1. Navigate without the arrow keys
- 2. Don’t use the backspace or delete keys
What are the keyboard shortcuts for the command-line?
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
- !! – run last command
- !blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
- !blah:p – print out the command that !blah would run (also adds it as the latest command in the command history)
- !$ – the last word of the previous command (same as Alt + .)
- !$:p – print out the word that !$ would substitute
- !* – the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘)
- !*:p – print out what !* would substitute
Nice! And is there a way to reach the ^U , that stty -a shows defined for SIGKILL on Linux, from bash? Preferrably without undefining the readline stuff (perhaps through a third mod/meta key). I assume it is only shadowed by the ctrl+u readline binding?
The kernel’s terminal driver ( termios ) interprets the special keys that can be typed to send a signal to a process, send end of file, erase characters, etc. This is basic Unix kernel functionality and very similar on most Unix and Linux implementations.
The stty command displays or sets the termios special characters, as well as other parameters for the terminal line driver.
Invoke stty -a to see the current values of the special characters and other «terminal line settings». In the following examples, you can see that intr is Ctrl + C , eof is Ctrl + D , susp is Ctrl + Z . (I’ve deleted other output to show only the special character settings):
stty -a special chars on GNU/Linux:
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
stty -a special characters on FreeBSD:
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = ^@; eol2 = ^@; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;
To change the value of a special character, for example, to change the interrupt character from Ctrl + C to Ctrl + E invoke stty like this ( ^E is literally two characters, the circumflex ( ^ ) followed by the letter E ):
For more information see the man pages for stty and termios . On GNU/Linux you can also look at the tty_ioctl man page.
The intr key ( Ctrl + C by default), doesn’t actually kill the process, but causes the kernel to send an interrupt signal ( SIGINT ) to all processes within the process group. The processes may arrange to catch or ignore the signal, but most processes will terminate, which is the default behavior.
The reason that Ctrl + d logs you out is because the terminal line driver sends EOF (end of file) on the standard input of the shell. The shell exits when it receives end of file on it’s standard input.
Useful Linux Command Line Bash Shortcuts You Should Know
In this article, we will share a number of Bash command-line shortcuts useful for any Linux user. These shortcuts allow you to easily and in a fast manner, perform certain activities such as accessing and running previously executed commands, opening an editor, editing/deleting/changing text on the command line, moving the cursor, controlling processes etc. on the command line.
Although this article will mostly benefit Linux beginners getting their way around with command line basics, those with intermediate skills and advanced users might also find it practically helpful. We will group the bash keyboard shortcuts according to categories as follows.
Launch an Editor
Open a terminal and press Ctrl+X and Ctrl+E to open an editor (nano editor) with an empty buffer. Bash will try to launch the editor defined by the $EDITOR environment variable.
Controlling The Screen
These shortcuts are used to control terminal screen output:
- Ctrl+L – clears the screen (same effect as the “clear” command).
- Ctrl+S – pause all command output to the screen. If you have executed a command that produces verbose, long output, use this to pause the output scrolling down the screen.
- Ctrl+Q – resume output to the screen after pausing it with Ctrl+S.
Move Cursor on The Command Line
The next shortcuts are used for moving the cursor within the command-line:
- Ctrl+A or Home – moves the cursor to the start of a line.
- Ctrl+E or End – moves the cursor to the end of the line.
- Ctrl+B or Left Arrow – moves the cursor back one character at a time.
- Ctrl+F or Right Arrow – moves the cursor forward one character at a time.
- Ctrl + Left Arrow or Alt+B or Esc and then B – moves the cursor back one word at a time.
- Ctrl + Right Arrow or Alt+C or Esc and then F – moves the cursor forward one word at a time.
Search Through Bash History
The following shortcuts are used for searching for commands in the bash history:
- Up arrow key – retrieves the previous command. If you press it constantly, it takes you through multiple commands in history, so you can find the one you want. Use the Down arrow to move in the reverse direction through the history.
- Ctrl+P and Ctrl+N – alternatives for the Up and Down arrow keys, respectively.
- Ctrl+R – starts a reverse search, through the bash history, simply type characters that should be unique to the command you want to find in the history.
- Ctrl+S – launches a forward search, through the bash history.
- Ctrl+G – quits reverse or forward search, through the bash history.
Delete Text on the Command Line
The following shortcuts are used for deleting text on the command line:
- Ctrl+D or Delete – remove or deletes the character under the cursor.
- Ctrl+K – removes all text from the cursor to the end of the line.
- Ctrl+X and then Backspace – removes all the text from the cursor to the beginning of the line.
Transpose Text or Change Case on the Command Line
These shortcuts will transpose or change the case of letters or words on the command line:
- Ctrl+T – transposes the character before the cursor with the character under the cursor.
- Esc and then T – transposes the two words immediately before (or under) the cursor.
- Esc and then U – transforms the text from the cursor to the end of the word to uppercase.
- Esc and then L – transforms the text from the cursor to the end of the word to lowercase.
- Esc and then C – changes the letter under the cursor (or the first letter of the next word) to uppercase, leaving the rest of the word unchanged.
Working With Processes in Linux
The following shortcuts help you to control running Linux processes.
- Ctrl+Z – suspend the current foreground process. This sends the SIGTSTP signal to the process. You can get the process back to the foreground later using the fg process_name (or %bgprocess_number like %1, %2 and so on) command.
- Ctrl+C – interrupt the current foreground process, by sending the SIGINT signal to it. The default behavior is to terminate a process gracefully, but the process can either honor or ignore it.
- Ctrl+D – exit the bash shell (same as running the exit command).
Bash Bang (!) Commands
In the final part of this article, we will explain some useful ! (bang) operations:
- !! – execute last command.
- !top – execute the most recent command that starts with ‘top’ (e.g. !).
- !top:p – displays the command that !top would run (also adds it as the latest command in the command history).
- !$ – execute the last word of the previous command (same as Alt +., e.g. if last command is ‘cat tecmint.txt’, then !$ would try to run ‘tecmint.txt’).
- !$:p – displays the word that !$ would execute.
- !* – displays the last word of the previous command.
- !*:p – displays the last word that !* would substitute.
For more information, see the bash man page:
That’s all for now! In this article, we shared some common and useful Bash command-line shortcuts and operations. Use the comment form below to make any additions or ask questions.
Common Linux command line shortcut keys
The common Linux commands in the last article sorted out the common Linux commands, and is continuing to supplement, today ready to sort out the common Linux command line shortcut keys, or the same reason, just want to record, operation, let more impressive, easy to find their own copy. And these commands must have the same effect, so I borrowed them directly from others.
Without further ado, let’s have a look!
First, mobile class
shortcuts | role |
---|---|
Ctrl + left and right keys | Move the word forward and backward |
Ctrl + A or Home | Move to command line (a: ahead) |
Ctrl + E or End | Move to end of command line (e: end) |
Ctrl + F or right arrow key | Move forward by character (f: forward) |
Ctrl + B or left arrow key | Move backward by character (b: Backward) |
Ctrl + x x | Move the cursor to the top of the line. Press again to jump the cursor back to the current position |
Second, editing class
shortcuts | role |
---|---|
Tab | auto-complete |
Ctrl + i | auto-complete |
Ctrl + d | Deletes a character backwards from the cursor |
Ctrl + h | Removes a character from the cursor forward |
Ctrl + w | Cut/delete from the cursor to the prefix |
Ctrl + u | Cut/delete from the cursor to the beginning of the line |
Ctrl + k | Cut/delete from the cursor to the end of the line |
Ctrl + y | Paste the use Ctrl + u Ctrl + k Ctrl + w Cut/delete text |
Alt + d | Delete from cursor to suffix |
Ctrl + t | Swaps characters at and before the cursor |
Alt + t | Swap the word before and at the cursor |
Alt + c | Change the uppercase word from the cursor |
Alt + u | Change the word from the cursor to all caps |
Alt + l | Change from cursor to all lowercase words |
Ctrl + o | Execute the current command and select the previous command |
Ctrl + l | Clear the screen clear |
Alt + Backspace | Delete the previous word |
Third, control class
shortcuts | role |
---|---|
Ctrl + s | Blocking screen output |
Ctrl + q | Allow screen output |
Ctrl + c | Terminate the command |
Ctrl + z | Hang the command |
Ctrl+d | You can exit the terminal if the command line is empty |
Ctrl+[ | It’s the Esc key |
Iv. History
shortcuts | role |
---|---|
Ctrl+ P or up arrow key | Last used history command (p: previous) |
Ctrl+ N or down arrow key | The next history command to use (n: next) |
Ctrl + r | Reverse search command history (R: Retrieve) |
Ctrl + G or Esc | Exit the historical search mode |
Alt + . | Use the last argument of the previous command |
5 ways to navigate the Linux terminal faster
Shortcut keys provide an easier and quicker method of navigating and executing commands on the command line.
One of the advantages of working in a terminal is that it’s faster than most other interfaces. Thanks to the GNU Readline library and the built-in syntax of shells like Bash and Zsh, there are several ways to make your interactions with the command line even faster. Here are five ways to make the most of your time in the terminal.
Great Linux resources
1. Navigate without the arrow keys
While executing commands on the command line, sometimes you miss a part at the beginning or forget to add certain tags or arguments toward the end. It’s common for users to use the Left and Right arrow keys on the keyboard to move through a command to make edits.
There’s a better way to get around the command line. You can move the cursor to the beginning of the line with CTRL+A. Similarly, use CTRL+E to move the cursor to the end of the line. Alt+F moves one word forward, and Alt+B moves one word back.
- Instead of Left arrow, left, left, left, use CTRL+A to go to the start of the line or Alt+B to move back one word.
- Instead of Right arrow, right, right, right, use CTRL+E to move to the end of the line, or Alt+F to move forward a word.
2. Don’t use the backspace or delete keys
It’s not uncommon to misspell commands. You might be used to using the Backspace key on the keyboard to delete characters in the backward direction and the Delete button to delete them in the forward direction. You can also do this task more efficiently and easily with some helpful keyboard shortcuts.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
Instead of deleting commands character by character, you can delete everything from the current cursor position to the beginning of the line or the end.
Use CTRL+U to erase everything from the current cursor position to the beginning of the line. Similarly, CTRL+K erases everything from the current cursor position to the end of the line.