Useful Linux Commands You Wish You Knew Earlier
The Linux commands people most often wish they had learned earlier are small time savers: Ctrl+R to search command history, cd - to jump back, !! to repeat the last command, tail -f and journalctl -f to watch logs live, grep -rn to search inside files, find with -mtime to locate recently changed files, du -sh and df -h to find what is filling a disk, ss -tulpn to see open ports, and man or --help to check options…
Topic: Linux Administration in IT Infrastructure · Commands & reference
Quick answer: The Linux commands people most often wish they had learned earlier are small time savers: Ctrl+R to search command history, cd - to jump back, !! to repeat the last command, tail -f and journalctl -f to watch logs live, grep -rn to search inside files, find with -mtime to locate recently changed files, du -sh and df -h to find what is filling a disk, ss -tulpn to see open ports, and man or --help to check options before running anything. All are safe, read-only or easily reversible.
Key takeaways
- Shell shortcuts save more time than memorising rare commands.
- Most examples here only read data; they do not change the system.
- Always check options with man or --help before using sudo.
- Log and port commands double as basic security checks.
- Options can differ slightly between distributions; test in a lab first.
Table of Contents
- Which Shell Shortcuts Save the Most Time?
- How Do You Find Files and Text Faster?
- How Do You Find What Is Filling the Disk?
- How Do You Watch Logs and Processes Live?
- Which Commands Show Network Activity?
- How Do Pipes Make Commands More Powerful?
- Which Habits Keep You Safe on the Command Line?
- References
Which Shell Shortcuts Save the Most Time?
| Shortcut | What it does |
|---|---|
| Ctrl+R | Search backwards through command history |
| !! | Repeat the previous command (for example sudo !!) |
| cd - | Return to the previous directory |
| Ctrl+A / Ctrl+E | Jump to the start or end of the line |
| Ctrl+L | Clear the screen |
| Tab Tab | Show completion options |
| history | tail -20 | Show the last 20 commands |
These come from Bash’s Readline and history features, documented in the GNU Bash manual.
How Do You Find Files and Text Faster?
grep -rn "error" /var/log/nginx/ # search text recursively with line numbers
grep -i "failed password" /var/log/auth.log
find /etc -name "*.conf" -mtime -1 # config files changed in the last day
find / -type f -size +500M 2>/dev/null # very large files
ls -lhtr # newest files last, human sizes
Options are explained in the GNU grep manual and GNU find manual. auth.log is the Debian and Ubuntu name; Red Hat family systems use /var/log/secure.
How Do You Find What Is Filling the Disk?
df -h # free space per filesystem
du -sh /var/* 2>/dev/null | sort -h # largest folders under /var
ncdu /var # interactive view, if installed
df, du and sort are part of GNU Coreutils.
How Do You Watch Logs and Processes Live?
tail -f /var/log/syslog
journalctl -u ssh -f # follow one service (sshd on some distros)
journalctl --since "1 hour ago" -p err
watch -n 2 free -h # repeat a command every 2 seconds
top # or htop if installed
See the journalctl documentation for filters by unit, priority and time.
Which Commands Show Network Activity?
| Command | Purpose |
|---|---|
| ip -br addr | Brief list of interfaces and addresses |
| ss -tulpn | Listening TCP and UDP ports with processes |
| sudo lsof -i :22 | Which process uses port 22 |
| curl -sI https://example.com | Fetch only HTTP response headers |
| dig example.com +short | Quick DNS answer |
The Linux man-pages project documents ss, ip and lsof.
How Do Pipes Make Commands More Powerful?
grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head
ps aux --sort=-%mem | head -5
some_command | tee output.txt
The first line counts failed SSH logins per source IP, a simple brute-force check. tee shows output and saves it at the same time. Use xargs only after previewing what it will act on.
For a broader reference list, read our guide to the most important Linux commands.
Which Habits Keep You Safe on the Command Line?
- Run
sudo -lto see what you are allowed to do before escalating. - Preview destructive actions: list files with
findbefore adding-delete, and userm -iwhen unsure. - Never pipe scripts from the internet straight into a shell without reading them.
- Avoid
chmod 777; our Linux file permissions guide explains safer modes. - Compare your settings with the CIS Benchmarks for your distribution.
To build confidence on real Linux servers, see our Linux administration and security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0