MervCodes

Tech Reviews From A Programmer

Linux Command Line Cheat Sheet: 50 Essential Commands

1 min read

Linux Command Line Cheat Sheet: 50 Essential Commands

The Linux command line is one of the most powerful tools you can master. While graphical interfaces come and go, the shell has remained remarkably stable for decades. Learn these commands once, and you'll use them for the rest of your career—on servers, containers, embedded devices, and your own laptop.

This cheat sheet covers 50 essential commands, grouped by what you're actually trying to do. Rather than dumping a raw list, each section explains when to reach for a command and includes a practical example you can adapt immediately.

Navigating the Filesystem

Before you can do anything, you need to move around and see where you are.

  • pwd — Print the working directory. Tells you exactly where you are.
  • ls — List directory contents. Use ls -lah for a detailed, human-readable view including hidden files.
  • cd — Change directory. cd - jumps back to your previous location, and cd ~ returns home.
  • tree — Display directories as a visual tree. Great for understanding project structure at a glance.
ls -lah /var/log     # Long listing, all files, human-readable sizes
cd ~/projects && pwd # Move and confirm location

Tip: ls -lt sorts by modification time, which is invaluable when hunting for the most recently changed file.

Working with Files and Directories

Creating, copying, moving, and deleting are daily operations.

  • touch — Create an empty file or update a file's timestamp.
  • mkdir — Make directories. Add -p to create nested paths in one shot.
  • cp — Copy files. Use -r for directories and -a to preserve permissions.
  • mv — Move or rename. There is no separate "rename" command in Linux.
  • rm — Remove files. rm -rf deletes recursively and forcefully—use with genuine caution.
  • ln — Create links. ln -s target linkname makes a symbolic link.
mkdir -p project/src/utils
cp -a config.yaml config.yaml.bak
mv draft.txt final.txt

Warning: rm -rf does not ask for confirmation and does not use a trash bin. Double-check the path before pressing Enter, especially when variables are involved.

Viewing and Editing File Contents

Reading files without opening a full editor keeps you fast.

  • cat — Concatenate and print file contents. Best for short files.
  • less — Page through large files interactively. Press q to quit, / to search.
  • head — Show the first lines (default 10). head -n 20 shows twenty.
  • tail — Show the last lines. tail -f follows a file live—perfect for watching logs.
  • nano — A beginner-friendly terminal editor.
  • vim — A powerful modal editor worth learning for the long haul.
tail -f /var/log/syslog     # Watch logs in real time
less +F access.log          # less in "follow" mode

Searching and Finding

When your filesystem grows, search becomes essential.

  • find — Locate files by name, size, age, or type.
  • grep — Search text using patterns. grep -r searches recursively.
  • locate — Fast filename search using a prebuilt database (run updatedb first).
  • which — Show the full path of an executable in your PATH.
  • wc — Count lines, words, and bytes. wc -l counts lines.
find . -name "*.log" -mtime +7 -delete   # Delete logs older than a week
grep -rin "error" /var/log/               # Recursive, case-insensitive, with line numbers

grep combined with pipes is the backbone of countless one-liners. Learn its -i, -v (invert), and -c (count) flags early.

Managing Processes

Every running program is a process you can inspect and control.

  • ps — Snapshot of running processes. ps aux shows everything.
  • top — Live, interactive process monitor.
  • htop — A friendlier, colorized top (install separately).
  • kill — Send a signal to a process by PID. kill -9 forces termination.
  • killall — Kill processes by name instead of PID.
  • jobs, bg, fg — Manage background and foreground jobs in your shell.
ps aux | grep nginx        # Find nginx processes
kill -15 4823              # Politely ask process 4823 to stop

Prefer signal 15 (SIGTERM) before 9 (SIGKILL). SIGTERM lets a program clean up; SIGKILL is the nuclear option.

Monitoring System Resources

Knowing what your system is doing prevents nasty surprises.

  • df — Report disk space usage. df -h is human-readable.
  • du — Estimate file and directory sizes. du -sh * summarizes each item in the current directory.
  • free — Show memory usage. Add -h for readable units.
  • uptime — Show how long the system has been running and its load averages.
  • uname — Print system information. uname -a shows everything.
df -h                      # Where is my disk space going?
du -sh * | sort -h         # Rank items in current dir by size

Permissions and Ownership

Linux security starts with who can read, write, and execute.

  • chmod — Change file permissions. chmod +x script.sh makes a script executable.
  • chown — Change ownership. chown user:group file sets both.
  • sudo — Execute a command as another user, usually root.
  • umask — Set default permissions for newly created files.
chmod 755 deploy.sh        # Owner full access; others read+execute
sudo chown -R www-data:www-data /var/www

Numeric permissions are worth memorizing: read is 4, write is 2, execute is 1. Add them per role—755 means owner 7 (4+2+1), group and others 5 (4+1).

Networking

Modern systems are always connected, and the shell speaks the network fluently.

  • ping — Test connectivity to a host.
  • curl — Transfer data from or to a server; indispensable for APIs.
  • wget — Download files non-interactively.
  • ssh — Securely connect to remote machines.
  • scp — Copy files securely between hosts.
  • ip — Show and manage network interfaces (ip addr).
curl -s https://httpbin.org/get | less
scp report.pdf user@server:/home/user/
ssh -p 2222 [email protected]

curl -I fetches only headers, which is a quick way to check status codes and redirects.

Archiving and Compression

Bundling and shrinking files is a routine part of backups and transfers.

  • tar — Archive multiple files. tar -czf creates a gzipped archive; tar -xzf extracts it.
  • gzip / gunzip — Compress or decompress individual files.
  • zip / unzip — Work with ZIP archives for cross-platform sharing.
tar -czf backup.tar.gz ~/documents
tar -xzf backup.tar.gz -C /tmp/restore

A memory aid for tar: "create, zip, file" and "extract, zip, file."

Shell Productivity Boosters

These commands and features multiply everything else you do.

  • history — Show past commands. Press Ctrl+R to search interactively.
  • alias — Create shortcuts, e.g. alias ll='ls -lah'.
  • man — Open the manual page for any command.
  • echo — Print text or variable values.
  • | (pipe) — Send one command's output into another—the foundation of shell power.
history | grep ssh         # Recall past ssh commands
alias gs='git status'      # Save keystrokes
man tar                    # Never memorize flags you can look up

Putting It Together

The real magic of the command line is composition. Individual commands are simple, but pipes let you chain them into custom tools. For example, to find the ten largest files in a directory tree:

find . -type f -exec du -h {} + | sort -rh | head -n 10

This single line finds every file, measures each, sorts by size descending, and shows the top ten—something no single command does alone. Once this pattern clicks, you'll start seeing the shell as a construction kit rather than a list of commands to memorize.

Practical Advice for Getting Fluent

  • Learn by doing. Pick one unfamiliar command each week and use it in real tasks.
  • Read the manual. man and --help answer most questions faster than a web search.
  • Build muscle memory. Aliases and Ctrl+R history search save thousands of keystrokes over time.
  • Fail safely. Test destructive commands like rm and find -delete with a harmless ls or echo first.
  • Keep this sheet handy. Nobody memorizes all 50 at once; reference it until the common ones stick.

Frequently Asked Questions

Do I need to memorize all 50 commands? No. Aim to internalize the dozen you use daily—ls, cd, cat, grep, find, cp, mv, rm, and a few others—and reference the rest as needed. Fluency comes from repetition, not cramming.

What's the difference between apt, yum, and dnf? These are package managers tied to different distributions: apt for Debian and Ubuntu, yum and its successor dnf for Red Hat, Fedora, and CentOS. They install, update, and remove software. Learn the one that matches your system.

Is the command line still relevant with modern GUIs? Absolutely. Servers, containers, and cloud instances are frequently headless, meaning the shell is your only interface. Automation, scripting, and remote administration all depend on it, and command-line skills transfer across every Linux system you'll ever touch.

How do I safely practice dangerous commands? Use a virtual machine, a container, or a disposable cloud instance. That way, a mistaken rm -rf costs you nothing. You can also preview what a command will affect by replacing the destructive action with echo or ls first.

What should I learn after these basics? Once comfortable, explore shell scripting with Bash, text processing with sed and awk, the tmux terminal multiplexer, and version control with git. These build directly on the foundation above and unlock serious automation.

Conclusion

These 50 commands cover the vast majority of everyday Linux work—navigating files, managing processes, monitoring resources, networking, and automating tasks. Don't try to swallow them all at once. Bookmark this cheat sheet, keep a terminal open, and reach for it whenever you're unsure. Within a few weeks of steady practice, the commands you once looked up will become second nature, and the command line will feel less like a wall and more like a superpower.

Sources

Related Articles