dotlinux blog

Useful Linux Command Line Bash Shortcuts You Should Know

The Linux command line (Bash) is a powerful tool for developers, system administrators, and power users. While it may seem intimidating at first, mastering Bash shortcuts can drastically boost your productivity, reduce errors, and make your workflow feel seamless. Whether you’re navigating directories, editing commands, or managing processes, these shortcuts will save you time and keystrokes.

This blog compiles the most essential Bash shortcuts, organized by use case, with clear examples and explanations. Even if you’re a seasoned user, you might discover new tricks to streamline your daily tasks. Let’s dive in!

2026-05

Table of Contents#

  1. Navigation Shortcuts

  2. Command Editing Shortcuts

  3. Command History Shortcuts

  4. Process Control Shortcuts

  5. File Management Shortcuts

  6. Advanced Shortcuts

  7. Conclusion

  8. Reference

1. Navigation Shortcuts#

Tab Completion#

Shortcut: Tab
What it does: Autocompletes commands, filenames, or directory names.
Example:
Type cd Doc and press Tab—Bash will automatically complete it to cd Documents/ (if that directory exists).
Why it’s useful: Saves time and reduces typos. Press Tab twice to see all possible matches if there are multiple options (e.g., cd Doc + Tab + Tab lists directories starting with "Doc").

Quick Directory Jumps#

  • cd ~ or cd: Jump to your home directory (e.g., /home/yourusername).
    Example: cd ~ → Moves to /home/alice.

  • cd ..: Move up one directory (parent directory).
    Example: If you’re in /home/alice/Documents, cd .. takes you to /home/alice.

  • cd -: Jump back to the previous directory.
    Example: After moving from /home/alice to /var/log, cd - returns to /home/alice.

Pushd and Popd for Directory Stacking#

  • pushd <directory>: Navigate to a directory and add the current directory to a "stack."
    Example: pushd /var/log → Moves to /var/log and saves your previous directory.

  • popd: Remove the top directory from the stack and navigate back to it.
    Example: After pushd /var/log, popd returns you to the directory you were in before.
    Why it’s useful: Ideal for switching between multiple directories without retyping paths.

2. Command Editing Shortcuts#

Move Cursor to Start/End of Line#

  • Ctrl + A: Move cursor to the start of the command line.
    Example: If you typed ls -l /long/path/to/file, Ctrl + A jumps to the beginning (ls).

  • Ctrl + E: Move cursor to the end of the command line.
    Example: From the start of ls -l /long/path/to/file, Ctrl + E jumps to the end (file).

Delete Text Efficiently#

  • Ctrl + U: Delete all text from the cursor to the start of the line.
    Example: If you typed sudo apt install wrongpackage, place the cursor after install and press Ctrl + U to delete sudo apt install .

  • Ctrl + K: Delete all text from the cursor to the end of the line.
    Example: In echo "Hello, world!", place the cursor after Hello, and press Ctrl + K to delete world!.

  • Ctrl + W: Delete the previous word (from the cursor backward).
    Example: In cd /home/alice/Documents, place the cursor at the end and press Ctrl + W repeatedly to delete Documents, then alice/, etc.

Jump Between Words#

  • Alt + B: Move cursor backward one word.
  • Alt + F: Move cursor forward one word.
    Example: In git commit -m "Fix bug", Alt + B from the end jumps to "Fix, then to -m, etc.

Undo Mistakes#

Shortcut: Ctrl + _ (or Ctrl + Shift + -)
What it does: Undo the last edit (works like "Ctrl + Z" in GUI apps).
Example: If you accidentally deleted text with Ctrl + U, Ctrl + _ restores it.

3. Command History Shortcuts#

Bash keeps a history of your commands (stored in ~/.bash_history). Use these shortcuts to reuse or search through past commands.

Search History with Reverse Lookup#

Shortcut: Ctrl + R
What it does: Open a reverse search prompt to find past commands.
Example: Press Ctrl + R, then type apt—Bash will show the most recent command containing "apt" (e.g., sudo apt update). Press Enter to run it, or Ctrl + R again to see older matches.

Repeat Recent Commands#

  • !!: Repeat the last command (pronounced "bang bang").
    Example: If you forgot sudo for apt update, run sudo !! to execute sudo apt update.

  • !n: Repeat the n-th command in history (find n with history).
    Example: history shows 500 ls -la, so !500 runs ls -la.

  • !-n: Repeat the command from n steps ago.
    Example: !-2 repeats the command before the last one.

Reuse Arguments from History#

  • !$: Reuse the last argument of the previous command.
    Example: After ls /var/log/syslog, cat !$ runs cat /var/log/syslog.

  • !*: Reuse all arguments of the previous command.
    Example: After cp file1.txt file2.txt /backup/, mv !* /new_backup/ runs mv file1.txt file2.txt /backup/ /new_backup/.

4. Process Control Shortcuts#

These shortcuts help manage running processes directly from the command line.

Terminate a Running Process#

Shortcut: Ctrl + C
What it does: Send an interrupt signal to the foreground process, stopping it.
Example: If ping google.com is running, Ctrl + C stops the ping.

Suspend and Resume Processes#

  • Ctrl + Z: Suspend the foreground process (sends it to the background).
    Example: Pause a long-running wget download with Ctrl + Z.

  • bg: Resume a suspended process in the background.
    Example: After Ctrl + Z on wget, run bg to let it continue downloading in the background.

  • fg: Bring a background process to the foreground.
    Example: fg %1 (replace 1 with the job number) brings the first background job back to the front.

List Background Jobs#

Shortcut: jobs
What it does: List all suspended or background processes.
Example:

$ jobs
[1]+  Stopped                 wget https://example.com/largefile.iso

Here, [1] is the job number, and you can resume it with fg %1.

5. File Management Shortcuts#

These shortcuts simplify working with files and directories using pattern matching and expansion.

Wildcards for Pattern Matching#

  • *: Matches any sequence of characters (including none).
    Example: ls *.txt lists all .txt files in the current directory.

  • ?: Matches exactly one character.
    Example: ls file?.txt matches file1.txt or fileA.txt but not file12.txt.

  • []: Matches one character from a set.
    Example: ls file[1-3].txt matches file1.txt, file2.txt, file3.txt.

Brace Expansion for Bulk Operations#

Syntax: {item1,item2,...} or {start..end}
What it does: Generates multiple arguments from a list or range.
Examples:

  • touch file{1..5}.txt creates file1.txt, file2.txt, ..., file5.txt.
  • cp report.{pdf,docx} copies report.pdf and report.docx (if they exist).

Tilde Expansion for Home Directories#

  • ~: Expands to your home directory (e.g., /home/alice).
    Example: cd ~/Documents is shorter than cd /home/alice/Documents.

  • ~username: Expands to another user’s home directory (if you have permission).
    Example: ls ~bob lists files in Bob’s home directory.

6. Advanced Shortcuts#

Clear the Screen#

Shortcut: Ctrl + L (or clear command)
What it does: Clears the terminal screen, similar to the clear command.
Why it’s useful: Keeps your terminal uncluttered without typing clear.

Exit the Shell#

Shortcut: Ctrl + D (or exit command)
What it does: Closes the current terminal session.
Example: Press Ctrl + D to log out of an SSH session or exit a terminal window.

Create Custom Aliases#

What it does: Define shortcuts for long or frequently used commands.
Example: Add this to your ~/.bashrc file to create a shortcut for ls -la:

alias ll='ls -la'

Reload the file with source ~/.bashrc, then run ll to list all files (including hidden ones) in long format.

Conclusion#

Mastering these Bash shortcuts will transform your command line experience from tedious to efficient. Start with the ones that align with your daily tasks (e.g., tab completion, Ctrl + R for history, or !! for repeating commands) and gradually incorporate more. With practice, these shortcuts will become muscle memory, saving you time and reducing frustration.

Reference#