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…

May 15, 2025 - 12:22
Updated: 
101.6k

Linux Administration in IT Infrastructure · Commands & reference

Useful Linux Commands You Wish You Knew Earlier

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?

ShortcutWhat it does
Ctrl+RSearch backwards through command history
!!Repeat the previous command (for example sudo !!)
cd -Return to the previous directory
Ctrl+A / Ctrl+EJump to the start or end of the line
Ctrl+LClear the screen
Tab TabShow completion options
history | tail -20Show 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?

CommandPurpose
ip -br addrBrief list of interfaces and addresses
ss -tulpnListening TCP and UDP ports with processes
sudo lsof -i :22Which process uses port 22
curl -sI https://example.comFetch only HTTP response headers
dig example.com +shortQuick 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 -l to see what you are allowed to do before escalating.
  • Preview destructive actions: list files with find before adding -delete, and use rm -i when 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

Press Ctrl+R in Bash and start typing; it searches backwards through history, and pressing Ctrl+R again finds older matches.

Run du -sh on the parent folder with a wildcard and pipe it to sort -h, then repeat inside the largest folder.

Use tail -f with the log file path, or journalctl -f on systemd systems, and press Ctrl+C to stop following.

The ss command from iproute2 replaces netstat; ss -tulpn lists listening TCP and UDP ports with the owning processes.

On Debian and Ubuntu they appear in /var/log/auth.log, on Red Hat family systems in /var/log/secure, and in journalctl.

Only after you understand them. Read the man page, test in a lab, and never pipe unknown scripts directly into a shell.

It reruns your previous command with sudo, which is handy when you forgot elevated rights, but check the command first.

It gives every user read, write and execute rights, which lets any account or compromised process modify the file.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.