Last modified: June 06, 2026
This article is written in: 🇺🇸
Let's talk about some seriously useful tricks that'll make your command-line life much easier. Ever find yourself thinking "I know I ran that command yesterday, but what was it again?" or "There has to be a faster way to do this!" Well, you're in luck, the terminal has some fantastic features to help you work smarter, not harder.
Think of your command history like a personal assistant that remembers everything you've typed. No more "What was that complex command I used last week?" moments!
Want to see your recent commands? It's simple:
history
You'll see a numbered list of commands you've run recently. Something like:
1 ls -la
2 cd Documents
3 grep "important" notes.txt
4 sudo apt update
...
Just want the highlights? Show only your last 20 commands:
history 20
Looking for something specific? Let's say you remember using git but can't recall the exact command:
history | grep "git"
This filters your history to show only commands containing "git". Pretty handy when you've run hundreds of commands!
The easy way, arrow keys:
The power-user way, reverse search. Here's where it gets really cool. Press Ctrl+R and start typing any part of a command you remember:
(reverse-i-search)git: git commit -m "Fix bug in login"
What's happening:
Ctrl+RCtrl+R to see other matchesEnter to run it, or Esc to cancelThis searches through your entire command history, not just what's visible on screen!
Method 1: By number
See that number next to each command in your history? You can run any command by its number:
!42
This runs whatever command #42 was. Great for running complex commands you don't want to retype.
Method 2: By starting letters
Remember the beginning of a command but not the whole thing?
!git
This runs the most recent command that started with "git". Super useful for commands you run frequently!
Made a small mistake in your last command? Don't retype the whole thing! Use this neat trick:
Say you just ran:
echo "Hello wrold"
Oops, typo! Just fix it like this:
^wrold^world
What just happened:
^old^new pattern finds "wrold" in your last commandecho "Hello world"Real-world example:
# Oops, wrong directory
cd /home/user/Docments
# Quick fix
^Docments^Documents
# Now you're in the right place!
History expansion lets you reuse parts of previous commands without retyping them. These shortcuts can save a lot of keystrokes, especially when working with long file paths or complex arguments.
Repeat the last command:
!!
This runs whatever you just executed. A common use case is when you forget sudo:
apt update
# Permission denied!
sudo !!
# Runs: sudo apt update
Grab the last argument from the previous command:
!$
Real scenario:
mkdir -p /var/www/mysite/assets
cd !$
# Runs: cd /var/www/mysite/assets
Grab the first argument:
!^
Grab all arguments from the previous command:
!*
Example:
echo one two three
cat !*
# Runs: cat one two three
Pick a specific argument by position:
!:2
The numbering starts at 0 (the command itself), so !:1 is the first argument, !:2 is the second, and so on.
Example:
cp /etc/hosts /tmp/hosts.bak
cat !:2
# Runs: cat /tmp/hosts.bak
Use arguments from a specific history entry:
!42:2
This grabs the second argument from command #42 in your history.
fcThe fc (fix command) built-in opens previous commands in your default text editor, letting you make changes before re-executing. This is especially helpful for long or complex commands.
Edit and re-run the last command:
fc
Your $EDITOR (or vi by default) opens with the last command. Save and quit to execute the edited version.
Edit a specific command from history:
fc 42
Opens command #42 for editing.
Edit a range of commands:
fc 10 20
Opens commands 10 through 20 in the editor. When you save and exit, all the commands run in sequence. This is useful for replaying a series of steps with modifications.
List recent history without editing (similar to history):
fc -l
fc -l -20
Sometimes you need to run sensitive commands (like those with passwords). Here's how to keep them private:
Start your command with a space, and it won't be saved to history:
mysql -u root -p secret_password
This only works if your shell is configured for it. Make sure you have:
export HISTCONTROL=ignorespace
Need a fresh start? Clear your current session's history:
history -c
Want to save your current session? Write it to your history file:
history -w
This updates your ~/.bash_history file with commands from your current session.
Just want to add to it? Append without overwriting:
history -a
This adds your current session's commands to the existing history file.
Start typing a command or filename and press Tab. The terminal will try to complete it for you:
# Type this:
cd Doc[Tab]
# It becomes:
cd Documents/
Not sure what's available? Press Tab twice to see all possibilities:
# Type this:
git [Tab][Tab]
# You'll see:
add branch commit push pull status log diff
Want even better auto-completion? Install bash-completion for smarter suggestions:
sudo apt install bash-completion
This gives you auto-completion for command options, package names, and much more. It's like having a built-in cheat sheet!
Auto-completion works for:
Here's the transformed version with natural, conversational language:
Think of manual pages (or "man pages") as having a comprehensive encyclopedia built right into your terminal. Whenever you're stuck on a command or want to learn what options are available, the manual is there to help. No internet required!
The basic approach is simple:
man ls
This opens up the complete manual for the ls command. You'll see everything, what it does, every possible option, examples, and even related commands.
You remember there's a way to make ls show file sizes in human-readable format, but you can't remember the flag. Just run man ls and search for "human" or "size" - you'll find the -h option quickly!
When you open a man page, you're actually using a program called less to view it. Here are the essential navigation tricks:
Moving around:
| Key | Action |
| Space bar | Jump down a full page (most useful) |
| Enter | Move down one line at a time |
| b | Go back up a page |
| g | Jump to the very beginning |
| G | Jump to the very end |
Searching like a detective:
| Key | Action |
| Space bar | Jump down a full page (most useful) |
| Enter | Move down one line at a time |
| b | Go back up a page |
| g | Jump to the very beginning |
| G | Jump to the very end |
/term |
Search forward for "term" |
?term |
Search backward for "term" |
| n | Go to next search result |
| N | Go to previous search result |
| q | Quit when you're done |
Let's say you want to find all the options for making ls show hidden files. Open man ls, then type /hidden and press Enter. The manual will jump right to the relevant section!
The manual is organized into numbered sections, kind of like different floors in a library:
| Section | What You'll Find | When You'd Use It |
| 1 | Regular commands you type | Most of the time ls, cp, grep, etc. |
| 2 | System calls (programming stuff) | When you're coding and need kernel functions |
| 3 | Library functions (more programming) | Programming with C libraries |
| 4 | Device files | Working with hardware devices |
| 5 | File formats | Understanding config files like /etc/passwd |
| 6 | Games | Yes, really! Try man 6 fortune |
| 7 | Miscellaneous | Special topics and conventions |
| 8 | Admin commands | System administration tools |
Sometimes the same name appears in multiple sections. For example:
man passwd # Shows the passwd command (section 1)
man 5 passwd # Shows the passwd file format (section 5)
The first tells you how to change passwords, the second explains the structure of the password file itself.
Want to see all sections for a topic?
man -a intro
This shows you the introduction page for each section, great for understanding what's available.
If you know what you want to do but can't remember the right command, use apropos.
apropos network
This searches command descriptions and lists tools related to your keyword. Think of it as asking Linux, "What commands are related to networking?"
Example output:
ifconfig (8) - configure a network interface
netstat (8) - print network connections and routing tables
ping (8) - send ICMP ECHO_REQUEST packets
wget (1) - non-interactive network downloader
If the results are too broad, you can narrow them down:
# Show only exact matches
apropos -e zip
# Show only commands from section 1
apropos -s 1 network
# Show commands whose names start with "git"
apropos -r '^git.*'
A common use case is when you know the task but not the command. For example, if you want to compress files but can't remember whether to use gzip, zip, or another tool:
apropos compress
apropos will display all commands related to compression, along with short descriptions, helping you quickly find the right tool.
You run:
apropos ssh
# nothing appropriate
but you know the system has an ssh manual page. That means your manual-page database is stale. Fix it in one step:
sudo mandb
This rebuilds the index (think of refreshing a library’s card catalog), so apropos will find newly installed or updated manual entries right away.
Quick reference without opening the full manual:
# Get a one-line description
whatis ls
# See what section a command is in
man -f passwd
Search multiple keywords:
# Find commands related to both "file" and "compress"
apropos file | grep compress
Custom manual paths:
If you've installed software in unusual locations:
sudo mandb -c /usr/local/share/man
Want more control over your shell history? A few Bash settings can make your command history cleaner, more useful, and a bit more private.
Control How Much History Bash Keeps
# Commands kept in memory during the current session
export HISTSIZE=1000
# Commands saved to the history file
export HISTFILESIZE=2000
HISTSIZE controls how many commands Bash remembers while you're working. HISTFILESIZE determines how many commands are stored in your history file (~/.bash_history) when the session ends.
Avoid Duplicate Entries
export HISTCONTROL=ignoredups
With this setting, Bash won't save consecutive duplicate commands, keeping your history less cluttered.
Skip Sensitive Commands
export HISTCONTROL=ignorespace
Commands that begin with a space won't be recorded in your history. This can be useful for one-off commands containing sensitive information.
For example:
echo "This won't be saved"
Combine Both Behaviors
export HISTCONTROL=ignoreboth
This is equivalent to enabling both ignoredups and ignorespace.
Add Timestamps to History
export HISTTIMEFORMAT="%F %T "
This displays the date and time alongside each history entry:
2025-07-26 14:30:15 git commit -m "Update docs"
2025-07-26 14:32:01 git push
Timestamps make it much easier to track when commands were run, especially when troubleshooting or reviewing past work.
To make these settings permanent, add them to your ~/.bashrc or ~/.bash_profile and reload the file:
source ~/.bashrc
Ready to feel like a command line wizard? These shortcuts will make you look like you've been using terminals for decades (even if you started yesterday).
Quick Navigation Tricks
| What You Want to Do | Magic Keys | Think of It Like |
| Jump to start of line | Ctrl+A |
"All the way to the beginning" |
| Jump to end of line | Ctrl+E |
"End of the line" |
| Hop back one word | Alt+B |
"Back one word" |
| Skip forward one word | Alt+F |
"Forward one word" |
Type a long command, then use Ctrl+A to zip to the beginning. It's oddly satisfying!
Quick Fixes for Command Mistakes
| When You Need To | Press This | What Happens |
| Delete everything after cursor | Ctrl+K |
"Kill everything to the right" |
| Delete everything before cursor | Ctrl+U |
"Undo everything to the left" |
| Delete the word behind cursor | Ctrl+W |
"Wipe out that word" |
| Bring back what you just deleted | Ctrl+Y |
"Yank it back" (like undo) |
Real scenario: You're typing a long command, realize you made a mistake at the beginning, hit Ctrl+U to clear it, then Ctrl+Y to bring it back and fix just the problem part. Smooth!
Emergency Buttons Every Terminal User Needs
| When Things Go Wrong | Your Lifeline | What It Does |
| Command is stuck/running forever | Ctrl+C |
"Cancel this madness!" |
| Want to pause something temporarily | Ctrl+Z |
"Zzz... put it to sleep" |
| Wake up that sleeping process | fg |
"Come back to the foreground" |
Common situation: You accidentally run a command that's taking forever. Don't panic! Ctrl+C is your friend, it's like hitting the emergency stop button.
Making These Settings Permanent
Want these tweaks to stick around? Add them to your shell configuration file:
# For bash users
echo 'export HISTSIZE=1000' >> ~/.bashrc
echo 'export HISTCONTROL=ignoreboth' >> ~/.bashrc
# Then reload your settings
source ~/.bashrc
The best way to remember these shortcuts? Use them! Start with just Ctrl+A and Ctrl+E for a few days, then gradually add more to your toolkit.
auditd for auditing commands and the shell’s built-in history functions. Create a file and attempt to trace back the command that created it using your findings.man command to display the manual page for the grep command. Read through the available options, and then practice by using grep to search for a specific term within a file on your system. Reflect on the value of the manual pages for command reference.HISTSIZE environment variable in your shell’s configuration file (such as ~/.bashrc), then reload the configuration file and confirm the new setting. Explore the benefits of having an extended command history for long-term use.history command. Use the output to review your recent activity, and then clear the history. Verify that the commands are no longer accessible by re-checking the history log.~/.bash_history) to confirm your previous commands were saved. Document how this process varies across different shells or configurations.HISTFILE and HISTCONTROL.Ctrl+R reverse search shortcut to quickly locate a past command by typing a keyword. Also, try using history | grep <keyword> to find specific commands from your history. Reflect on which method feels more efficient and why.HISTCONTROL variable by setting it to ignoredups or ignoreboth in your shell configuration file. Test this by entering duplicate commands and confirming that they are not saved in your history.HISTIGNORE variable to filter out commands like ls, cd, and exit automatically. Check your history to verify the exclusions.PROMPT_COMMAND and the history -a command to append each command to the history file as you execute it. Experiment with shopt -s histappend to ensure history entries from all sessions are preserved when you close them, and reflect on how this might benefit your workflow.