11 Useful Terminal Tricks to Work Faster


Most Developers spend more time getting around their Terminal rather than actually using it. To help you get most out of your Terminal, we have included some smart tips to help you save countless keystrokes; complete repetitive tasks in half the time and boost your efficiency. The guide will provide you with 11 smart Terminal tricks which are used by experienced Linux users on a daily basis, along with real-world example copy/pastes for each trick for Ubuntu, Rocky Linux & Arch. If you are just getting started, the Linux commands for beginners guide is a good place to start before diving in here.

Note:

All tricks in this guide work on Bash and Zsh unless stated otherwise. To check which shell you are running, type echo $SHELL in your terminal.

Examples


#01

Why Most Developers Stay Slow

Before getting into the tricks, it helps to understand the exact habits that keep most terminal users stuck at beginner speed. These are the patterns identifies as the core problems:

  • Repeating long commands manually instead of recalling them from history
  • Using the arrow keys to find history instead of reverse search
  • Too much mouse usage when keyboard navigation is faster
  • Opening too many terminal tabs instead of using tmux sessions and panes : covered in Trick 6: Tmux Keeps Your Work Alive below
  • No shell customization : no aliases, no functions, no config

The terminal is an environment, not just a tool. Once you treat it that way and invest a small amount of time setting it up properly, every session after that runs faster. The 11 tricks below address each one of these problems directly.


#02

Trick 1 : Reuse Commands Instantly

The most common terminal time waster is retyping a command you just ran. Three shortcuts eliminate this completely.

I. sudo !! : Re-run Last Command as Root

When a command fails because you forgot sudo, do not retype it. Just run sudo !! and the shell expands !! to your full previous command automatically.

Before (slow): Pressing up arrow, then Home, then typing sudo at the front.

After (fast):

bash
LinuxTeck.com
apt update # fails: permission denied
sudo !! # expands to: sudo apt update

# The shell prints what it is about to run before executing:
# sudo apt update

Warning:

Before you type sudo !! : always verify what !! will expand to. If your last command had a destructive typo such as rm -rf / tmp/test (notice the rogue space) instead of rm -rf /tmp/test, running sudo !! would execute that broken command as root with no second prompt and no undo. One bad space can wipe a filesystem.

Senior Pro-Tip:

Make !!:p a habit before every sudo !!. The :p modifier prints the full history expansion to screen without executing it, so you can read it with your own eyes before committing to root access. Treat it like a final review step : print first, run second. Senior engineers do this automatically. It costs one extra keystroke and can prevent catastrophic mistakes on production systems.

bash
LinuxTeck.com
# !!:p — print what !! would run WITHOUT executing it
!!:p
# Output: apt update

# Once verified, THEN run it with sudo
sudo !!
# Runs: sudo apt update

# Especially useful after long or complex commands
# where you want to verify before giving root access

II. cd !$ : Jump to the Last Argument You Used

!$ gives you the last argument from your previous command. If you just ran ls on a directory and now want to go into it, use cd !$. No retyping the path.

bash
LinuxTeck.com
ls /var/log/nginx
cd !$ # expands to: cd /var/log/nginx

# Works with any command
stat /etc/hosts
vim !$ # expands to: vim /etc/hosts

# Alt+. pastes the last argument inline — you see it before pressing Enter

Tip:

Many pros prefer Alt+. (dot) over !$ for daily use. Both insert the last argument, but Alt+. pastes it directly into your command line so you can see and edit it before pressing Enter. The key difference: pressing Alt+. a second time replaces it with the last argument from the command before that, a third press goes one further back, and so on : letting you cycle through the last arguments of your entire recent history without ever pressing Ctrl+R. It is faster and safer when working with long or sensitive paths.

III. history | tail : See Your Most Recent Commands Fast

bash
LinuxTeck.com
# View last 10 commands
history | tail -10

# View last 20 commands
history | tail -20

# Search history for a specific command
history | grep docker

# Run a command by its history number
!142

Output
138 git status
139 git add .
140 git commit -m "fix nginx config"
141 git push origin main
142 sudo systemctl restart nginx

#03

Trick 2 : Search Command History Faster

The arrow key approach to history is slow. Once your history has more than a few dozen entries, you need a smarter way to find past commands. Ctrl+R is the built-in answer, and a few ~/.bashrc settings make it dramatically more useful.

IV. Ctrl+R : Reverse History Search

Press Ctrl+R and start typing any part of a past command. The shell searches backwards through your history and shows the closest match instantly. Press Ctrl+R again to go further back. Press Enter to run the match or the right arrow to edit it first.

bash
LinuxTeck.com
# Press Ctrl+R then type part of a past command
# Terminal shows:
(reverse-i-search)`nginx': sudo systemctl restart nginx

# Press Ctrl+R again to go to an older match
# Press Enter to run it
# Press right arrow to edit before running
# Press Ctrl+G to cancel search

V. Bonus Settings : Make History Actually Useful

The default Bash history size of 1000 lines fills up fast on any active system. These three settings expand your history dramatically and prevent duplicate entries from cluttering your search results. Add them to your ~/.bashrc or ~/.zshrc.

bash
LinuxTeck.com
# Add to ~/.bashrc or ~/.zshrc
HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoredups:erasedups

# Apply without restarting terminal
source ~/.bashrc

# Verify
echo $HISTSIZE

Output
10000

Tip:

HISTCONTROL=ignoredups:erasedups keeps your history clean by removing consecutive duplicate entries and erasing older duplicates from the file. This makes Ctrl+R results much less cluttered. Also remember: pressing Ctrl+R repeatedly cycles backward through all previous matches for the same search term : most beginners stop at the first result and miss older, more relevant commands.

Note:

Zsh users: Consider installing the zsh-autosuggestions plugin. It displays a faint grey shadow of your most recent matching history entry as you type, so you can accept it with the right arrow key without pressing Ctrl+R at all. It is the natural next step once you have mastered these 11 tricks. Install with: git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions then add source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh to your ~/.zshrc.


#04

Trick 3 : Fix Mistakes Without Retyping

When you make a typo in a long command and run it, most people press up arrow, navigate to the mistake with arrow keys, fix it, and press Enter again. There is a faster way: the caret substitution syntax ^old^new lets you correct the last command by replacing just the part that was wrong.

bash
LinuxTeck.com
# You ran this with a typo:
git chekcout main
# error: did not match any file(s) known to git

# Fix it with caret substitution — no retyping:
^chekcout^checkout
# Runs: git checkout main

# Another example:
^statsu^status
# Runs: git status

# Real-world example — you mistyped systemctl (extra 'l' at the end):
# NOTE: 'systemctll' below is a deliberate typo — not a real command
systemctll restart nginx # bash: systemctll: command not found
^systemctll^systemctl # Corrects to: systemctl restart nginx

Note:

Caret substitution only replaces the first occurrence of the typo in the command. It is faster than editing manually and great for long, complex commands where you only need to fix one word. systemctll in the example above is intentionally misspelled to demonstrate the fix : it is not a real command.


#05

Trick 4 : Aliases Remove Repetitive Work

An alias is a short name for a command you type regularly. Once you add it to your shell config file it is available every session without any extra setup. Anything repeated often deserves an alias. For more on automating shell workflows, the Linux bash scripting automation guide covers this in depth.

bash
LinuxTeck.com
# Open your shell config
nano ~/.bashrc # Bash
nano ~/.zshrc # Zsh

# Add these aliases at the bottom:
alias gs='git status' # Git status (short)
alias ll='ls -alF' # Detailed listing
alias gp='git push' # Git push current branch
alias dps='docker ps' # List Docker containers
alias reload='source ~/.bashrc' # Reload shell config

# Save and apply immediately
source ~/.bashrc

# List all current aliases
alias

# Remove a temporary alias
unalias gs

Warning:

Aliases typed directly into the terminal are temporary and disappear when the session ends. Always add permanent aliases to ~/.bashrc or ~/.zshrc and run source ~/.bashrc after saving.


#06

Trick 5 : Keyboard Shortcuts That Matter

These shortcuts come from Emacs keybindings and are built into Bash and Zsh. No install needed. They work on every Linux box you will ever log into. Keyboard navigation is faster than arrow keys for anything beyond moving one character at a time.

bash
LinuxTeck.com
# LINE NAVIGATION
Ctrl+A # Jump to start of line
Ctrl+E # Jump to end of line

# WORD NAVIGATION
Alt+F # Jump to next word
Alt+B # Jump to previous word

# DELETE
Ctrl+W # Delete previous word
Ctrl+K # Clear everything after cursor
Ctrl+U # Clear everything before cursor

# SCREEN
Ctrl+L # Clear the screen
Ctrl+C # Cancel current process


#07

Trick 6 : Tmux Keeps Your Work Alive

Tmux is a terminal multiplexer. It lets you run multiple terminal sessions inside a single window, split the screen into panes, and keep sessions alive after you disconnect. If you are working on a remote server and your SSH connection drops, a tmux session keeps running and you can reattach to it. This is one of the most important tools for anyone doing remote Linux work.

bash
LinuxTeck.com
# Install tmux
# Ubuntu / Debian
sudo apt install tmux

# Rocky Linux / RHEL
sudo dnf install tmux

# Arch Linux
sudo pacman -S tmux

# SESSION MANAGEMENT
tmux new -s project # Create new named session
tmux ls # List all sessions
tmux attach -t project # Reattach to session

# INSIDE TMUX — prefix is Ctrl+B
Ctrl+B, D # Detach (session keeps running)
Ctrl+B, % # Split pane vertically
Ctrl+B, " # Split pane horizontally
Ctrl+B, arrow keys # Move between panes
Ctrl+B, x # Kill current pane

Tip:

Tmux sessions survive disconnections, support split panes for multitasking, and are essential for remote server work. Run long tasks inside a tmux session and detach safely : your job keeps running even if your SSH session drops.


#08

Trick 7 : Run Jobs in the Background

When you start a long-running process in the terminal, it locks up the prompt until it finishes. Background job control lets you keep the terminal usable while tasks run in parallel. This is the built-in alternative to tmux for quick background tasks that do not need a persistent session.

bash
LinuxTeck.com
# Start a process in the background with &
npm run build &

# List all background jobs
jobs

# Bring most recent background job to foreground
fg

# Bring a specific job to foreground (job number from jobs)
fg %2

# Suspend a running foreground job
Ctrl+Z

# Resume it in background
bg %1

Output
[1] + running npm run build
[2] - stopped vim server.conf

#09

Trick 8 : Build Smarter Shell Functions

When an alias is not enough because you need to accept arguments or run multiple steps, a shell function handles the job. Functions live in the same config file as your aliases. The infographic example shows a function that combines navigation and listing into a single command. For deeper reading on writing reusable shell functions, the bash scripting guide walks through the full syntax.

bash
LinuxTeck.com
#!/bin/bash
# Add to ~/.bashrc or ~/.zshrc

# cl — cd into a directory and list its contents
function cl() {
cd "$1" && ls -la
}

# Usage: cl /var/log

# mkcd — create a directory and cd into it
function mkcd() {
mkdir -p "$1" && cd "$1"
}

# extract — handle any archive format
function extract() {
case "$1" in
*.tar.gz) tar -xzf "$1" ;;
*.zip) unzip "$1" ;;
*) echo "Unsupported: $1" ;;
esac
}


#10

Trick 9 : fzf Makes Your Terminal Searchable

fzf is an interactive fuzzy finder that works with files, history, git branches, processes, and anything that produces a list. Once installed it replaces the default Ctrl+R history search with a full-screen popup, and adds Ctrl+T for fuzzy file search. It is one of the highest-value single installs available for Linux terminal users in 2025.

bash
LinuxTeck.com
# Install fzf
# Ubuntu / Debian
sudo apt install fzf

# Rocky Linux / RHEL (enable EPEL first)
sudo dnf install epel-release && sudo dnf install fzf

# Arch Linux
sudo pacman -S fzf

# Enable key bindings in ~/.bashrc
[ -f /usr/share/doc/fzf/examples/key-bindings.bash ] && \
source /usr/share/doc/fzf/examples/key-bindings.bash
source ~/.bashrc

# Select a git branch interactively
git branch | fzf

# Open a file with vim using fuzzy search
vim $(fzf)

# Search through history interactively
history | fzf

Tip:

fzf provides interactive fuzzy search for files, git branches, history, and more. Install it on every machine you work on regularly. The key binding integration alone makes Ctrl+R dramatically more useful than the default reverse search.


#11

Trick 10 : Copy Terminal Output Without the Mouse

Copying output from the terminal by highlighting with a mouse and using the right-click menu is slow and breaks your keyboard flow. Linux has clipboard tools that let you pipe command output directly to the clipboard from the terminal. The right tool depends on your display server: X11, Wayland, or macOS.

bash
LinuxTeck.com
# Install xclip (X11 — most desktop Linux)
# Ubuntu / Debian
sudo apt install xclip

# Rocky Linux / RHEL
sudo dnf install xclip

# COPY file contents to clipboard (X11)
cat file.txt | xclip -selection clipboard

# Copy SSH public key to clipboard (X11)
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard

# For Wayland — use wl-copy
cat file.txt | wl-copy

# Check your display server
echo $XDG_SESSION_TYPE

Output
x11

Note:

Use xclip on X11 systems, wl-copy on Wayland systems, and pbcopy on macOS. If you are not sure which display server you are running, echo $XDG_SESSION_TYPE will tell you. Most modern Ubuntu desktops from 22.04 onwards use Wayland by default.


#12

Senior Terminal Habits vs Common Beginner Mistakes

The infographic separates experienced terminal users from beginners not by which commands they know but by the habits they have built. These patterns are worth internalizing.

What senior developers do:

  • Prefer keyboard over mouse for everything that can be done without it
  • Customize the shell environment with aliases, functions, and history settings
  • Use history tools actively instead of retyping commands
  • Automate repetitive tasks rather than tolerating them
  • Keep sessions persistent with tmux so disconnections never lose progress

What beginners keep doing wrong:

  • Repeating commands manually every time instead of recalling them
  • Ignoring shell history entirely and relying only on memory
  • Opening too many terminal tabs instead of using tmux panes
  • Never setting up aliases or shortcuts and accepting slow workflows
  • Working without tmux on remote servers and losing work on disconnection

Small terminal optimizations really do save hours every month. The key is consistency. Build muscle memory with daily practice and the speed gains compound over time.


#13

Troubleshooting Common Problems

This section covers the issues that come up most often when applying these tricks for the first time.

Problem 1: Alias Not Saving After Reboot

You added an alias directly in the terminal and it disappeared after restarting. Aliases typed directly into the terminal are session-only. They must go in ~/.bashrc or ~/.zshrc to persist.

bash
LinuxTeck.com
# Wrong — session only, gone on next login:
alias gs='git status'

# Right — add permanently:
echo "alias gs='git status'" >> ~/.bashrc
source ~/.bashrc

# Verify
alias | grep gs

Problem 2: Ctrl+R Not Working in Zsh

On fresh Zsh installs without Oh My Zsh, Ctrl+R may not trigger history search. Fix it by adding the correct bindkey line to your ~/.zshrc.

bash
LinuxTeck.com
# Add to ~/.zshrc
bindkey -e
bindkey "^R" history-incremental-search-backward

# Reload
source ~/.zshrc

# Or install fzf which fixes it automatically for both Bash and Zsh

Problem 3: xclip Not Working (No Display)

On headless servers or SSH sessions, xclip fails with a "Can't open display" error because there is no graphical environment. Use xclip only on local desktop sessions. For remote work, pipe output to a file and copy from there, or use tmux copy mode.

bash
LinuxTeck.com
# On a remote server — save to file instead
cat /etc/nginx/nginx.conf > /tmp/nginx_copy.txt

# In tmux — use copy mode
# Ctrl+B then [ to enter copy mode
# Space to start selection, Enter to copy
# Ctrl+B then ] to paste

# Check if you have a display available
echo $DISPLAY


#14

Why These Tricks Actually Matter

Every trick in this guide reduces what engineers call "toil" : the repetitive, low-value work that eats up time without producing anything. When you use !! instead of retyping a sudo command you save maybe five seconds. That does not sound like much. But across a full working day with dozens of terminal interactions, those savings add up. They also reduce errors: recalling commands from history is more accurate than retyping them from memory.

Beyond raw speed, there is a mental cost to fighting your tools. Every time you have to stop and retype a long path, scroll through cluttered output, or wait for a locked terminal to finish, you break your concentration. The tricks in this guide keep your focus on the actual problem rather than on the mechanics of the terminal. Over months of daily use that difference is noticeable. As the infographic puts it: consistency beats speed. Build muscle memory through daily practice and the results compound.


Key Takeaways

  • sudo !! fixes the most common mistake : forgetting sudo : without retyping anything.
  • !$ and Alt+. reuse the last argument from the previous command, saving repeated typing of long paths.
  • history | tail gives you a quick view of recent commands without searching through everything.
  • Ctrl+R is the single most underused built-in shortcut. Use it for every history lookup.
  • Set HISTSIZE=10000 and HISTCONTROL=ignoredups:erasedups in your config to make history actually searchable.
  • ^old^new caret substitution corrects a typo in the last command without pressing up arrow or retyping.
  • Aliases go in ~/.bashrc or ~/.zshrc. Typing them in the terminal makes them temporary only.
  • Keyboard shortcuts like Ctrl+A, Ctrl+E, Ctrl+W, and Alt+F require zero setup and work on every Linux system.
  • Tmux keeps sessions alive through SSH disconnections and makes parallel work possible without extra tabs.
  • fzf is the highest single-install value for terminal productivity in 2025. Install it on every machine you use regularly.
  • Use xclip on X11 or wl-copy on Wayland to pipe terminal output directly to the clipboard without touching the mouse.

Explore more advanced Linux shell tools

People Also Ask

How do I search command history in Linux?

Press Ctrl+R in your terminal and start typing any part of the command you are looking for. The shell searches backwards through your history and shows the closest match instantly. Press Ctrl+R again to cycle through older matches. Press Enter to run the matched command, or the right arrow key to edit it first. To make this work better, set HISTSIZE=10000 and HISTCONTROL=ignoredups:erasedups in your ~/.bashrc so your history is large and clean. For an even better experience, install fzf which replaces Ctrl+R with a full-screen fuzzy search popup.

How do I save an alias permanently in Linux?

Open your shell configuration file with nano ~/.bashrc for Bash or nano ~/.zshrc for Zsh. Add your alias at the bottom in the format alias name='command'. Save the file, then run source ~/.bashrc to apply the change immediately without restarting the terminal. If you type an alias directly into the terminal without adding it to the config file, it will disappear the moment you close that session. Running alias with no arguments lists all currently active aliases so you can verify it loaded correctly.

What does !! do in Linux terminal?

!! is a history expansion shortcut that represents your entire last command. The most common use case is running sudo !! after a command fails because you forgot sudo. Instead of pressing up arrow and adding sudo manually, you just type sudo !! and the shell expands it to sudo your-last-command automatically. The shell always prints the expanded command before executing it so you can see exactly what is about to run. This works in Bash and most other shells on Linux.

How do I run the last command as sudo in Linux?

Type sudo !! and press Enter. The !! expands to your full previous command, so the result is sudo your-previous-command. This is the standard fix for the very common situation of forgetting to use sudo. The shell prints the expanded command before running so you can confirm it looks right. This works in Bash. In Zsh the same syntax works but you may need to enable extended globbing depending on your configuration.

What is the fastest way to navigate directories in Linux?

For quick back-and-forth navigation, cd - takes you to the previous directory instantly. For multi-step navigation, pushd and popd let you maintain a stack of directories. For the most efficient overall experience, install fzf and use Alt+C for interactive fuzzy directory jumping, or install zoxide and use the z command which learns your most-visited directories over time. After using it for a few days, you can jump to any directory by typing just a fragment of its name from anywhere in the filesystem.

What are the most useful Linux terminal shortcuts?

The shortcuts with the most practical return are: Ctrl+R for history search, Ctrl+A and Ctrl+E to jump to the start and end of a line, Ctrl+W to delete the last word, Ctrl+U to clear everything before the cursor, Alt+F and Alt+B to move forward and backward one word at a time, and Ctrl+L to clear the screen. All of these are built into the readline library used by Bash and Zsh, which means they work on every Linux system without any configuration or installation.


LinuxTeck : A Complete Linux Learning Blog
From your first terminal command to advanced sysadmin skills : every guide here is written in plain English with real examples you can run right now.

About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.

L