Last modified: August 22, 2025
This article is written in: 🇺🇸
Getting Around Like a Pro
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.
Your Command History is Your Friend
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!
See What You've Been Up To
Want to see your recent commands? It's simple:
history
What 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!
Navigate Your History Like a Time Traveler
The easy way - arrow keys: - ↑ (Up arrow): Go back through previous commands - ↓ (Down arrow): Go forward through your history
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:
- You pressed Ctrl+R
- You started typing "git"
- The terminal found the most recent command containing "git"
- Keep pressing Ctrl+R
to see other matches
- Press Enter
to run it, or Esc
to cancel
Pro tip: This searches through your entire command history, not just what's visible on screen!
Run Previous Commands Without Retyping
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!
Quick Fixes for Typos
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:
- The ^old^new
pattern finds "wrold" in your last command
- Replaces it with "world"
- Runs the corrected command: echo "Hello world"
Real-world example:
# Oops, wrong directory
cd /home/user/Docments
# Quick fix
^Docments^Documents
# Now you're in the right place!
Keeping Secrets Out of History
Sometimes you need to run sensitive commands (like those with passwords). Here's how to keep them private:
The space trick: Start your command with a space, and it won't be saved to history:
mysql -u root -p secret_password
Note: This only works if your shell is configured for it. Make sure you have:
export HISTCONTROL=ignorespace
Managing Your Command History
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.
Auto-Complete: Your Typing Shortcut
The Tab key is magic!
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!
Pro tip: Auto-completion works for:
- Command names
- File and directory names
- Command options (--help, -v, etc.)
- Package names (when installing software)
- Git branches and remotes
- SSH hostnames from your config
Here's the transformed version with natural, conversational language:
The Manual Pages: Your Built-in Documentation Library
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!
Getting Help When You Need It
The basic approach is simple:
man ls
What happens:
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.
Real-world scenario:
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!
Finding Your Way Around Manual Pages
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:
- 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:
- /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
Pro tip: 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's Organization System
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 |
Why does this matter? 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.
Searching When You Don't Know the Exact Command
The scenario: You know you want to do something network-related, but you're not sure which command to use.
The solution - apropos
:
apropos network
What you'll get: A list of all commands related to networking, with brief descriptions. It's like asking "Show me everything that has to do with networks."
Sample output:
ifconfig (8) - configure a network interface
netstat (8) - Print network connections, routing tables
ping (8) - send ICMP ECHO_REQUEST to network hosts
wget (1) - The non-interactive network downloader
Getting more specific:
Sometimes apropos
returns too many results. Here's how to narrow it down:
# Only show exact matches for "zip"
apropos -e zip
# Only show commands (section 1)
apropos -s 1 network
# Use patterns - show everything starting with "git"
apropos -r '^git.*'
Real-world example:
You want to compress files but can't remember if it's gzip
, zip
, or something else:
apropos compress
You'll see all compression-related commands with descriptions, making it easy to pick the right one.
When Things Don't Work as Expected
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.
Power User Tips
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
Level Up Your Command Line Skills
Ever wish you could customize how your shell remembers the commands you type? Let's dive into some neat tricks that'll make your terminal experience much smoother!
Setting Your Memory Limits
# Keep 1000 commands in memory while you're working
export HISTSIZE=1000
# Save 2000 commands to your history file for later
export HISTFILESIZE=2000
What's happening here? HISTSIZE is like your assistant's short-term memory (what it remembers right now), while HISTFILESIZE is the long-term memory (what gets saved when you close the terminal).
Getting Rid of Annoying Duplicates
# Stop recording the same command over and over
export HISTCONTROL=ignoredups
No more seeing ls
repeated 20 times when you hit the up arrow!
Creating a "Private Mode" for Sensitive Commands
# Commands starting with a space won't be saved
export HISTCONTROL=ignorespace
Start any command with a space when typing passwords or sensitive info, and it won't show up in your history. Pretty neat, right?
The Best of Both Worlds
# Ignore duplicates AND space-prefixed commands
export HISTCONTROL=ignoreboth
Adding Timestamps (Because When Did I Run That?)
# Add date and time to your history
export HISTTIMEFORMAT="%F %T "
Now you'll see: Instead of just git commit
, you'll see 2025-07-26 14:30:15 git commit
- super helpful when you're trying to figure out when you did something!
Keyboard Moves
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
Practice Makes Perfect
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.
Challenges
- Investigate whether it is possible to identify the exact command used to create a specific file. Explore tools such as
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. - Use the
man
command to display the manual page for thegrep
command. Read through the available options, and then practice by usinggrep
to search for a specific term within a file on your system. Reflect on the value of the manual pages for command reference. - Increase the command history size in your shell to 5000 entries. Modify the
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. - Display the last ten commands you’ve executed using the
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. - Examine where and how command history is saved when you close a shell session. Close a terminal, reopen it, and check the history file (e.g.,
~/.bash_history
) to confirm your previous commands were saved. Document how this process varies across different shells or configurations. - Open multiple terminal sessions and explore how command history is managed across them. Run several commands in each session and then close the terminals in various orders. Reopen a new session to see which commands have been saved and explore any settings that might influence this, such as
HISTFILE
andHISTCONTROL
. - Explore different methods to search through your command history. Practice using the
Ctrl+R
reverse search shortcut to quickly locate a past command by typing a keyword. Also, try usinghistory | grep <keyword>
to find specific commands from your history. Reflect on which method feels more efficient and why. - Configure your shell to ignore duplicate commands in the history to keep it clean and concise. Modify the
HISTCONTROL
variable by setting it toignoredups
orignoreboth
in your shell configuration file. Test this by entering duplicate commands and confirming that they are not saved in your history. - Find a way to exclude specific commands from being saved in your history. Experiment with prefacing a command with a space to prevent it from being recorded. Additionally, try setting the
HISTIGNORE
variable to filter out commands likels
,cd
, andexit
automatically. Check your history to verify the exclusions. - Set up a shared command history across multiple terminal sessions. Explore the use of
PROMPT_COMMAND
and thehistory -a
command to append each command to the history file as you execute it. Experiment withshopt -s histappend
to ensure history entries from all sessions are preserved when you close them, and reflect on how this might benefit your workflow.