Skip to main content

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!

These shortcuts help you move around and edit your command line efficiently.

ShortcutDescription
Ctrl+AMove cursor to the beginning of the line
Ctrl+EMove cursor to the end of the line
Alt+BMove cursor back one word
Alt+FMove cursor forward one word
Ctrl+BMove cursor back one character
Ctrl+FMove cursor forward one character

Example:

Imagine you're typing a long command and need to change something at the beginning:

bash
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:

bash
sudo apt-get install python3-pip python3-dev build-essential

Text Manipulation Shortcuts

These shortcuts help you edit text quickly without using the mouse.

ShortcutDescription
Ctrl+KCut text from cursor to the end of line
Ctrl+UCut text from cursor to the beginning of line
Ctrl+WCut the word before the cursor
Ctrl+YPaste the last cut text
Alt+DDelete the word after the cursor
Ctrl+DDelete the character under the cursor
Ctrl+HDelete the character before the cursor (same as Backspace)
Ctrl+TSwap the character under cursor with the previous one
Alt+TSwap the current word with the previous one
Alt+UCapitalize from cursor to the end of the word
Alt+LConvert to lowercase from cursor to the end of the word
Alt+CCapitalize 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:

bash
apt update && apt upgarde

You notice that "upgarde" is misspelled. You can:

  1. Press Ctrl+A to go to the beginning
  2. Press Alt+F multiple times to navigate to "upgarde"
  3. Press Ctrl+W to delete the misspelled word
  4. Type the correct "upgrade"

Process Control Shortcuts

These shortcuts help you manage running processes in the terminal.

ShortcutDescription
Ctrl+CTerminate the current running process
Ctrl+ZSuspend the current process (can be resumed with fg command)
Ctrl+DExit the current shell (same as typing exit command)
Ctrl+SStop output to screen (useful for long outputs)
Ctrl+QResume output to screen (after using Ctrl+S)

Example:

If you start a command that takes too long or is producing too much output:

bash
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:

bash
# 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.

ShortcutDescription
Ctrl+LClear the screen (same as clear command)
Ctrl+Shift+TOpen a new tab in the terminal window
Ctrl+Shift+NOpen a new terminal window
Alt+[Number]Switch to tab number [Number]
Ctrl+Shift+WClose the current tab
Ctrl+Shift+QClose 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.

ShortcutDescription
Ctrl+RSearch command history (reverse-search)
Ctrl+GExit history search mode
Ctrl+P or Up ArrowPrevious command in history
Ctrl+N or Down ArrowNext 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
!stringRun the most recent command that starts with "string"
!?string?Run the most recent command that contains "string"
!nRun 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":

  1. Press Ctrl+R to enter reverse search mode
  2. Type "docker"
  3. Press Enter when you find the command you want to run
  4. 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:

bash
# 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:

ShortcutDescription
TabAuto-complete commands, filenames, and directories
Tab Tab (double tap)Show all possible completions

Example:

Start typing a command or path and press Tab:

bash
# 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:

  1. Open your .bashrc file:

    bash
    nano ~/.bashrc
  2. Add your custom alias or function:

    bash
    # Custom shortcuts
    alias ll='ls -la'
    alias update='sudo apt update && sudo apt upgrade'
  3. Save and reload your configuration:

    bash
    source ~/.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:

ShortcutDescription
Ctrl+B %Split the window vertically
Ctrl+B "Split the window horizontally
Ctrl+B Arrow KeyNavigate between panes
Ctrl+B cCreate a new window
Ctrl+B nMove to the next window
Ctrl+B pMove to the previous window

To install Tmux:

bash
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:
    bash
    sudo apt install readline-common
  • Try interactive shortcut trainers like shortcutfoo.com (external website)

Exercises

  1. Muscle Memory Training: Practice using Ctrl+A, Ctrl+E, Ctrl+K, and Ctrl+Y when editing command lines until they become second nature.

  2. History Challenge: Try using Ctrl+R to find and reuse at least five different commands from your history.

  3. Alias Creation: Create at least three custom aliases for commands you use frequently and add them to your .bashrc file.

  4. Tab Completion Race: Time yourself completing a series of commands with and without using tab completion to see the time difference.

  5. 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! :)