Ubuntu Terminal Shortcuts
Terminal shortcuts can dramatically improve your productivity when working with the Ubuntu command line. These keyboard combinations allow you to navigate, edit, and control your terminal environment efficiently without reaching for the mouse.
Introduction
The Ubuntu Terminal (or command line interface) is a powerful tool for interacting with your system. However, typing every command character by character can be time-consuming. Terminal shortcuts provide a way to perform common actions quickly, making your workflow more efficient.
In this guide, we'll explore essential shortcuts organized by category:
- Navigation shortcuts
- Text manipulation shortcuts
- Process control shortcuts
- Terminal session shortcuts
- History shortcuts
Let's dive in and supercharge your terminal skills!
Navigation Shortcuts
These shortcuts help you move around and edit your command line efficiently.
Shortcut | Description |
---|---|
Ctrl+A | Move cursor to the beginning of the line |
Ctrl+E | Move cursor to the end of the line |
Alt+B | Move cursor back one word |
Alt+F | Move cursor forward one word |
Ctrl+B | Move cursor back one character |
Ctrl+F | Move cursor forward one character |
Example:
Imagine you're typing a long command and need to change something at the beginning:
apt-get install python3-pip python3-dev build-essential
Instead of pressing the left arrow multiple times, simply press Ctrl+A
to jump to the beginning, then you can add sudo
before the command:
sudo apt-get install python3-pip python3-dev build-essential
Text Manipulation Shortcuts
These shortcuts help you edit text quickly without using the mouse.
Shortcut | Description |
---|---|
Ctrl+K | Cut text from cursor to the end of line |
Ctrl+U | Cut text from cursor to the beginning of line |
Ctrl+W | Cut the word before the cursor |
Ctrl+Y | Paste the last cut text |
Alt+D | Delete the word after the cursor |
Ctrl+D | Delete the character under the cursor |
Ctrl+H | Delete the character before the cursor (same as Backspace) |
Ctrl+T | Swap the character under cursor with the previous one |
Alt+T | Swap the current word with the previous one |
Alt+U | Capitalize from cursor to the end of the word |
Alt+L | Convert to lowercase from cursor to the end of the word |
Alt+C | Capitalize the character under the cursor and move to the end of the word |
Example:
Let's say you've typed a command but need to modify it:
apt update && apt upgarde
You notice that "upgarde" is misspelled. You can:
- Press
Ctrl+A
to go to the beginning - Press
Alt+F
multiple times to navigate to "upgarde" - Press
Ctrl+W
to delete the misspelled word - Type the correct "upgrade"
Process Control Shortcuts
These shortcuts help you manage running processes in the terminal.
Shortcut | Description |
---|---|
Ctrl+C | Terminate the current running process |
Ctrl+Z | Suspend the current process (can be resumed with fg command) |
Ctrl+D | Exit the current shell (same as typing exit command) |
Ctrl+S | Stop output to screen (useful for long outputs) |
Ctrl+Q | Resume output to screen (after using Ctrl+S ) |
Example:
If you start a command that takes too long or is producing too much output:
find / -name "*.txt"
You can press Ctrl+C
to stop it immediately, or press Ctrl+Z
to suspend it. When a process is suspended, you can:
# View suspended jobs
jobs
# Resume the process in the background
bg
# Resume the process in the foreground
fg
Terminal Session Shortcuts
These shortcuts help you manage your terminal window.
Shortcut | Description |
---|---|
Ctrl+L | Clear the screen (same as clear command) |
Ctrl+Shift+T | Open a new tab in the terminal window |
Ctrl+Shift+N | Open a new terminal window |
Alt+[Number] | Switch to tab number [Number] |
Ctrl+Shift+W | Close the current tab |
Ctrl+Shift+Q | Close the entire terminal window |
Example:
When your terminal gets cluttered with output, instead of typing "clear", simply press Ctrl+L
to get a clean screen.
History Shortcuts
These shortcuts help you navigate and use your command history.
Shortcut | Description |
---|---|
Ctrl+R | Search command history (reverse-search) |
Ctrl+G | Exit history search mode |
Ctrl+P or Up Arrow | Previous command in history |
Ctrl+N or Down Arrow | Next command in history |
Alt+. or Esc+. | Use the last word of the previous command |
!! | Repeat the last command |
!$ | Refer to the last argument of the previous command |
!string | Run the most recent command that starts with "string" |
!?string? | Run the most recent command that contains "string" |
!n | Run the command with number "n" from history list |
!# | Refer to the entire current command line |
Example:
Let's say you want to find a command you ran previously that included "docker":
- Press
Ctrl+R
to enter reverse search mode - Type "docker"
- Press
Enter
when you find the command you want to run - Or press
Ctrl+G
to exit the search without running a command
Another useful example is when you need to use the same argument in multiple commands:
# First command
mkdir -p /var/www/myproject
# Then use Alt+. to get the last argument
cd Alt+.
# This becomes: cd /var/www/myproject
Tab Completion
While not a keyboard shortcut in the traditional sense, tab completion is one of the most powerful time-saving features in the terminal:
Shortcut | Description |
---|---|
Tab | Auto-complete commands, filenames, and directories |
Tab Tab (double tap) | Show all possible completions |
Example:
Start typing a command or path and press Tab:
# Start typing
cd /etc/net
# Press Tab to auto-complete
cd /etc/network/
# Press Tab twice to see all options in the network directory
cd /etc/network/ Tab Tab
Custom Terminal Shortcuts
You can create your own shortcuts by adding them to your .bashrc
or .bash_profile
file. Here's how:
-
Open your
.bashrc
file:bashnano ~/.bashrc
-
Add your custom alias or function:
bash# Custom shortcuts
alias ll='ls -la'
alias update='sudo apt update && sudo apt upgrade' -
Save and reload your configuration:
bashsource ~/.bashrc
Now you can type ll
instead of ls -la
or update
to run both update commands at once.
Terminal Multiplexing with Tmux
For advanced terminal users, Tmux provides even more powerful shortcuts through its multiplexer capabilities. Some basic Tmux shortcuts include:
Shortcut | Description |
---|---|
Ctrl+B % | Split the window vertically |
Ctrl+B " | Split the window horizontally |
Ctrl+B Arrow Key | Navigate between panes |
Ctrl+B c | Create a new window |
Ctrl+B n | Move to the next window |
Ctrl+B p | Move to the previous window |
To install Tmux:
sudo apt install tmux
Summary
Mastering Ubuntu Terminal shortcuts can significantly increase your productivity and make command-line work more enjoyable. The key categories we've covered are:
- Navigation shortcuts for moving around the command line
- Text manipulation shortcuts for editing commands efficiently
- Process control shortcuts for managing running processes
- Terminal session shortcuts for window/tab management
- History shortcuts for navigating and reusing past commands
Learning these shortcuts may take some practice, but the time savings are substantial once they become muscle memory.
Additional Resources
- Run
man bash
in your terminal to access the complete Bash manual - Practice with
readline
by installing the package:bashsudo apt install readline-common
- Try interactive shortcut trainers like
shortcutfoo.com
(external website)
Exercises
-
Muscle Memory Training: Practice using
Ctrl+A
,Ctrl+E
,Ctrl+K
, andCtrl+Y
when editing command lines until they become second nature. -
History Challenge: Try using
Ctrl+R
to find and reuse at least five different commands from your history. -
Alias Creation: Create at least three custom aliases for commands you use frequently and add them to your
.bashrc
file. -
Tab Completion Race: Time yourself completing a series of commands with and without using tab completion to see the time difference.
-
Terminal Session Management: Practice opening, organizing, and navigating between multiple terminal tabs using only keyboard shortcuts.
If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)