21 Useful Terminal Shortcuts Pro Linux Users Love to Use
Sure, learning the Linux commands should always be your priority but once you get a grip on the command line, there’s one other thing you should focus on.
Terminal shortcuts!
You have no idea how helpful they are until you know how to use them to make your terminal sessions super productive.
So in this tutorial, I will walk you through the top terminal shortcuts with examples of how to use them.
Before I explain all the shortcuts individually, here’s a cheat sheet of what I’ll be discussing in this tutorial:
Shortcut | Description |
---|---|
Ctrl + A | Move to the start of the line. |
Ctrl + E | Move to the end of the line. |
Ctrl + U | Delete from the cursor to the start of the line. |
Ctrl + K | Delete from the cursor to the end of the line. |
Ctrl + W | Delete the word before the cursor. |
Ctrl + L | Clear the terminal screen. |
Ctrl + C | Stop the current process/command. |
Ctrl + D | Log out or exit the terminal. |
Ctrl + Z | Pause the current process (can be resumed). |
Ctrl + R | Search command history (backward search). |
Up Arrow | Show the previous command (from the command history). |
Down Arrow | Show the next command (from the command history). |
!! | Repeat the last command. |
!n | Repeat the nth command from history. |
Tab | Auto-complete commands, files, or directories. |
Tab twice | List all possible completions. |
Ctrl + Shift + C | Copy the selected text or command. |
Ctrl + Shift + V | Paste copied text or command. |
Ctrl + Shift + N | Open a new terminal window. |
Ctrl + Shift + T | Open a new tab in the terminal. |
Ctrl + Tab orCtrl + PageDown | Switch between terminal tabs. |
Now, let’s have a look at them individually.
1. Ctrl + A: Move to the start of the line
When you press the Ctrl + A
, it will shift the cursor to the beginning of the file which can be really helpful when you write a long command and want to make changes at the beginning of the line.
For example. here, I’ve demonstrated how you can press the Ctrl + A
anywhere and it will shift you to the beginning of the line:
2. Ctrl + E: Move to the end of the line
While using the terminal if you want to jump to the end of the line, you can simply press the Ctrl + E
and it will do the job.
In the following example, I used a sample text and pressed Ctrl + E
to get to the end of the line:
3. Ctrl + U: Delete from the cursor to start
There are times when you want to remove everything from the cursor position to the beginning of the line.
In that case, all you have to do is use the left arrow keys to place the cursor from where you would like to delete to the start of the line and then press Ctrl + U
:
4. Ctrl + K: Delete from the cursor to the end
As you can guess from the title, when you press the Ctrl + K
, it will remove everything from the cursor to the end of the line (everything from the cursor position to the right-hand side).
To use this shortcut, first, you have to place your cursor from where you want to remove text to the end and then press the Ctrl + K
as shown here:
5. Ctrl + W: Delete a single word before the cursor
This is what I use daily as I often mistype commands and want to remove one part of the command for that, you can simply press the Ctrl + W
.
When you press the Ctrl + W
key, it will only remove a single word before the cursor:
6. Ctrl + L: Clear terminal screen (kind of)
It does not clear the terminal screen in a true manner but declutters the screen and if you scroll up, you will still find the previous command and execution history.
Yes, it is different than the clear
command as it removes the history and you will find the execution of the clear
command in the command history.
But when you press Ctrl + L
, it just declutters your current screen and you won’t find it inside of the history (as it is not a command itself).
For example, here, I executed the history command and then pressed the Ctrl + L
key to clear the screen:
7. Ctrl +C: Stop the current process/execution
How many times did it happen when you wanted to stop the command execution and you had no idea how to do it and ended up closing the terminal itself?
Well, in any case, all you have to do is press Ctrl + C
.
When you press the keys, it sends the SIGINT
signal that will eventually kill the process.
For example, here, I killed the ongoing point command execution:
In the end, you’ll see the ^C
symbol indicating you pressed the Ctrl + C
to kill the ongoing execution.
But there are several processes that may not be killed using the Ctrl + C
signal and in that case, you can use the other termination signals in Linux:
8. Ctrl + D: Logout or exit from the terminal
You can always use the exit command to close a shell session and terminal. You can also use the Ctrl+D shortcut keys as well.
When you press the Ctrl + D
, it will log you out from the ongoing session if you use it in SSH, it will close the session and if pressed again, it will close the terminal itself:
9. Ctrl + Z: Pause the current process
Killing an ongoing process is not a good idea always as you have to start over again.
So in that case, what you can do is press Ctrl + Z
to stop the ongoing process and later on can be continued from where it was left.
For example, here, I stopped the update process:
Want to know more ways to stop ongoing processes and how to resume them? Here’s a detailed guide for that purpose:
10. Ctrl + R: Search command history
When you press Ctrl + R
, it opens a search mode prompt from where you can type any part of the command and it will find you the command with matching string you’ve entered.
Once you find that command, you simply press the Enter
key and it will execute that command.
For example, here, I searched for the update
and it gave me the command to update the repository in Ubuntu (sudo apt update):
11. Up Arrow: Show the previous command from history
When you press the Up Arrow
key, it will show you previously executed commands one by one from the command history:
12. Down Arrow: Show the next command from history
When you press the Up Arrow
key, it shows you previous commands but there are times when you accidentally press it many times and now you want to show the previously shown command.
In that case, you can use the Down Arrow
key.
In the following illustration, first I pressed the up arrow key multiple times, and then to come back to previously shown commands, I pressed the down arrow key:
13. !!: Repeat the last command
There are times when you want to execute the most recent command one or more times and in that case, you can simply type !!
(exclamation twice):
!!
For example, here, I executed an echo command and then used the !!
twice to use the same command again and again:
But the most common and useful execution of this shortcut is when you forget to use sudo with a command. Instead of writing the entire command again, you just use sudo !!
14. !n: Repeat the nth command from history
You can access the history of executed commands by simply executing the bash history command in the terminal and each will have an index number associated with it:
history
Now, let’s suppose I want to execute the 2nd last echo command, then I will be using the following:
!1998
15. Tab: Auto-complete the command
I think I should have started the terminal shortcuts list with this one.
While typing a long command, you can type half of it and then press the Tab
key and it will auto-complete for you.
For example, here, I pressed the Tab
key to auto-complete my script execution:
16. Tab (twice): List all the possible auto-completes
If pressing the Tab
key does not work, it means there are multiple possibilities of the currently typed command.
In that case, what you can do is press the Tab
key twice to list all the possibilities:
17. Ctrl + Shift + C: Copy the selected text
To copy the text in the terminal, you have to select the text using the mouse and then press the Ctrl + Shift + C
to copy the selected text:
18. Ctrl + Shift + V: Paste the copied text
Once you copy the text by selecting the text and pressing Ctrl + Shift + C
, now you can paste it anywhere by pressing Ctrl + Shift + V
:
19. Ctrl + Shift + N: Open a new terminal window
When you press the Ctrl + Shift + N
, it will open a new terminal window with the same working directory you were working in the previous window:
20. Ctrl + Shift + T: Open new tab
Like web browsers, in the terminal, you can open tabs to separate different tasks. To open a new tab, all you have to do is press Ctrl + Shift + T
:
21. Ctrl + Tab or Ctrl + PageDown: Switch tabs
If you created multiple tabs using the above method, you may want to switch between them.
And for that purpose, you can use Ctrl + Tab
or Ctrl + PageDown
:
New Book: Efficient Linux at the Command Line
Pretty amazing Linux book with lots of practical tips. It fills in the gap, even for experienced Linux users. Must have in your collection.
Get it from Amazon
Next: Must-know Linux commands
Liked this list of ‘essential’ keyboard shortcuts? Perhaps you would like this list of the most basic yet essential Linux commands:
I understand that you may not remember all of these terminals shortcuts, at least not initially. But practice them and gradually they will be in your muscle memory.
By the way, do you have some of your favourite shortcuts that have not been included here? Share it in the comments?