DevOps

Linux Commands Master Cheat Sheet

A copy-paste-ready reference for everyday Linux work, from moving around the filesystem to debugging a live server.

·
7 min read
·
AI-assisted

AI tooling disclosure

Generative AI materially contributed to this article.

Human review confirmed by the author.

Linux Commands Master Cheat Sheet

Why You Need a Cheat Sheet

Linux runs most of the world's servers, cloud infrastructure, containers, and developer machines. Whether you are a student, a developer, or a sysadmin, the terminal is where work gets done fast. But nobody memorizes every flag of every command.

This guide collects the commands you will actually use, grouped by task, with short examples you can paste straight into your shell. Bookmark it, print it, and come back whenever you blank on a flag.

Golden rule: when you are stuck, ask the system itself.

man ls              # full manual page for a command
ls --help           # quick usage summary
whatis grep         # one-line description

1. Navigation

pwd                 # print current directory
ls                  # list files
ls -lah             # long format, hidden files, human-readable sizes
cd /var/log         # go to an absolute path
cd ~                # go to your home directory
cd -                # jump back to the previous directory
cd ..               # go up one level
tree -L 2           # directory tree, 2 levels deep (may need installing)

2. Files and Directories

touch notes.txt             # create an empty file or update its timestamp
mkdir projects              # create a directory
mkdir -p a/b/c              # create nested directories in one go
cp file.txt backup.txt      # copy a file
cp -r src/ src_backup/      # copy a directory recursively
mv old.txt new.txt          # rename or move
rm file.txt                 # delete a file
rm -r folder/               # delete a directory and its contents
ln -s /path/to/target link  # create a symbolic link

Warning: there is no recycle bin in the terminal. rm -rf deletes immediately and permanently. Double-check the path, especially when using wildcards or sudo.

3. Viewing File Contents

cat file.txt            # print the whole file
less file.txt           # scroll through a file (q to quit, / to search)
head -n 20 file.txt     # first 20 lines
tail -n 20 file.txt     # last 20 lines
tail -f app.log         # follow a log file live
wc -l file.txt          # count lines
nl file.txt             # print with line numbers

4. Searching

Finding files

find . -name '*.log'                 # by name
find /var -type d -name 'cache'      # directories only
find . -size +100M                   # files larger than 100 MB
find . -mtime -7                     # modified in the last 7 days
find . -name '*.tmp' -delete         # find and delete
locate nginx.conf                    # fast lookup using an index (run updatedb first)
which python3                        # where an executable lives

Searching inside files

grep 'error' app.log                 # lines containing 'error'
grep -i 'error' app.log              # case-insensitive
grep -rn 'TODO' ./src                # recursive, with line numbers
grep -v 'debug' app.log              # lines NOT containing 'debug'
grep -c 'error' app.log              # count matching lines
grep -E 'warn|error|fatal' app.log   # extended regex

5. Text Processing

These small tools become powerful when you connect them with pipes (|).

sort names.txt                       # sort lines
sort -n numbers.txt                  # numeric sort
sort file.txt | uniq -c              # count duplicate lines
cut -d',' -f1,3 data.csv             # columns 1 and 3 of a CSV
awk '{print $1, $NF}' file.txt       # first and last field of each line
sed 's/old/new/g' file.txt           # replace text (prints result)
sed -i 's/old/new/g' file.txt        # replace text in place
tr 'a-z' 'A-Z' < file.txt            # convert to uppercase
ls | xargs -n1 echo                  # run a command once per input line
command | tee output.txt             # show output AND save it to a file

6. Permissions and Ownership

Run ls -l and you will see something like -rwxr-xr--. Those characters are permissions for the owner, the group, and everyone else.

  • r (read) = 4

  • w (write) = 2

  • x (execute) = 1

Add the numbers for each class: 755 means the owner can read, write, and execute, while the group and others can read and execute.

chmod 755 script.sh          # numeric mode
chmod +x script.sh           # make a file executable
chmod -R 644 docs/           # apply recursively
chown alice file.txt         # change owner
chown alice:devs file.txt    # change owner and group
sudo command                 # run a command as root

Common values: 644 for regular files, 755 for scripts and directories, 600 for private files such as SSH keys.

7. Process Management

ps aux                       # all running processes
ps aux | grep nginx          # find a specific process
top                          # live process monitor (q to quit)
htop                         # friendlier alternative (may need installing)
kill 1234                    # politely ask process 1234 to stop
kill -9 1234                 # force kill (last resort)
pkill firefox                # kill by name
command &                    # run in the background
jobs                         # list background jobs
fg %1                        # bring job 1 to the foreground
nohup ./script.sh &          # keep running after you log out

Services with systemd

systemctl status nginx       # check a service
sudo systemctl start nginx   # start
sudo systemctl stop nginx    # stop
sudo systemctl restart nginx # restart
sudo systemctl enable nginx  # start at boot
journalctl -u nginx -f       # follow a service's logs

8. Disk and Memory

df -h                        # disk space per filesystem
du -sh folder/               # total size of a folder
du -h --max-depth=1 .        # size of each subfolder
free -h                      # memory and swap usage
lsblk                        # list block devices and partitions
mount | column -t            # show mounted filesystems

9. Networking

ip a                         # network interfaces and IP addresses
ping -c 4 google.com         # test connectivity (4 packets)
curl https://example.com     # fetch a URL
curl -I https://example.com  # headers only
curl -o file.zip URL         # download to a file
wget URL                     # download a file
ss -tulpn                    # listening ports and their processes
dig example.com              # DNS lookup
traceroute example.com       # trace the network path

Remote access and file transfer

ssh user@server              # log in to a remote machine
ssh -i ~/.ssh/key user@host  # use a specific key
scp file.txt user@host:/tmp/ # copy a file to a remote machine
rsync -avz src/ user@host:/backup/   # efficient sync, only sends changes
ssh-keygen -t ed25519        # generate a modern SSH key pair

10. Archives and Compression

tar -czvf backup.tar.gz folder/   # create a gzip archive
tar -xzvf backup.tar.gz           # extract it
tar -tzvf backup.tar.gz           # list contents without extracting
gzip file.txt                     # compress (creates file.txt.gz)
gunzip file.txt.gz                # decompress
zip -r archive.zip folder/        # create a zip
unzip archive.zip                 # extract a zip

Memory trick for tar: create, extract, test/list, z for gzip, verbose, file.

11. Package Management

The command depends on your distribution.

Debian / Ubuntu (apt)

sudo apt update              # refresh package lists
sudo apt upgrade             # upgrade installed packages
sudo apt install git         # install
sudo apt remove git          # remove
apt search keyword           # search

Fedora / RHEL / Rocky (dnf)

sudo dnf install git
sudo dnf remove git
sudo dnf upgrade

Arch (pacman)

sudo pacman -Syu             # sync and upgrade everything
sudo pacman -S git           # install
sudo pacman -Rns git         # remove with unused dependencies

12. Users and System Information

whoami                       # current user
id                           # user ID and groups
uname -a                     # kernel and system info
hostnamectl                  # hostname and OS details
uptime                       # how long the system has been up, plus load
lscpu                        # CPU details
date                         # current date and time
sudo adduser bob             # create a user (Debian/Ubuntu)
sudo passwd bob              # set or change a password
sudo usermod -aG sudo bob    # add a user to the sudo group
history | tail -20           # recent commands

13. Redirection, Pipes, and Shortcuts

Redirection

command > out.txt            # write output to a file (overwrites)
command >> out.txt           # append to a file
command 2> errors.txt        # send errors to a file
command > all.txt 2>&1       # send output and errors to one file
command1 | command2          # pipe output into another command
command1 && command2         # run command2 only if command1 succeeds

Keyboard shortcuts that save hours

  • Tab autocompletes commands and file names

  • Ctrl + C stops the running command

  • Ctrl + R searches your command history

  • Ctrl + A / Ctrl + E jumps to the start / end of the line

  • Ctrl + L clears the screen

  • Ctrl + D logs out or ends input

  • !! repeats the previous command (try sudo !! after forgetting sudo)

14. Handy One-Liners

# 10 largest files and folders under the current directory
du -ah . | sort -rh | head -10

# Which process is using port 8080?
ss -tulpn | grep 8080

# Watch a log for errors in real time
tail -f app.log | grep -i error

# Count lines of Python code in a project
find . -name '*.py' | xargs wc -l

# Replace text across many files
grep -rl 'old_text' . | xargs sed -i 's/old_text/new_text/g'

# Back up a file with today's date
cp config.conf config.conf.$(date +%F)

# Show the 10 most used commands in your history
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10

Safety Habits Worth Building

  1. Preview before you destroy. Run ls or find with the same pattern before you add rm or -delete.

  2. Be careful with sudo. It bypasses the safety rails. Know exactly what a command does before running it as root.

  3. Back up before editing system files. For example, sudo cp /etc/fstab /etc/fstab.bak.

  4. Quote your variables and patterns. rm $dir/* with an empty $dir is a classic disaster.

  5. Never paste commands you do not understand. Check them with man or --help first.

Final Thoughts

You do not need to memorize everything here. Learn the handful of commands you use daily, such as cd, ls, grep, find, tail -f, and ssh, and let the rest live in this cheat sheet. Over time, chaining small commands with pipes will start to feel natural, and that is where the Linux terminal really shines.

Pick three commands from this list that you have never used and try them today. That is the fastest way to turn a cheat sheet into real skill.

Comments(0)

Join the discussion by logging into your account.

No comments yet. Be the first to comment!

Arpan Singh

Passionate developer sharing knowledge about modern web technologies and best practices.

Subscribe to Arpan Singh's Newsletter

Direct email dispatches when new stories are published. Zero algorithms.