iZONE

Linux Commands Cheatsheet

A practical Linux commands guide covering file management, terminal workflows, permissions, networking, processes, and system administration.

Resources

What is Linux?

Linux is an operating system, just like Windows or macOS. The difference? You control it by typing commands. And honestly — that's what makes it so powerful once you get used to it.

the three layers — kernel, shell, terminal

kernelthe engine
  • The core of Linux — talks directly to hardware.
  • You never interact with it directly.
shellthe interpreter
  • Reads your commands and sends them to the kernel.
  • Bash is the most common shell. Zsh is popular too.
terminalwhere you type
  • The window where you type commands.
  • Also called: command line, console, CLI.

anatomy of a command

Bash

# structure:
# command  -flag  argument

# 𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖
# list files in a folder
ls -l /home

# command = ls
# flag    = -l  (long format)
# argument= /home  (the folder)

# 𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖𝄖
# copy a file
cp -r myfolder/ backup/

# command  = cp
# flag     = -r  (recursive)
# arguments= myfolder/  backup/

get help for any command

Bash

# short help — fits on one screen
ls --help

# full manual page
# press q to quit
man ls

# search inside man page
# press / then type your search word
man grep

# if you only remember part of a command name
apropos "copy file"
# shows all commands related to that topic

Navigating the File System

Everything in Linux is a file — programs, settings, even hardware devices. Knowing how to move around is the first real skill to lock in.

pwd, ls, cd — the three you use every day

Bash

# where am I right now?
pwd
# output: /home/alice

# what's in the current folder?
ls

# show hidden files too (files starting with .)
ls -a

# show details: size, permissions, date
ls -l

# combine flags
ls -la

# move into a folder
cd Documents

# move into a nested folder
cd Documents/projects

absolute vs relative paths

Bash

# absolute path — starts from root /
cd /home/alice/Documents

# relative path — starts from where you are
cd Documents

# go up one folder
cd ..

# go up two folders
cd ../..

# go to your home folder (fastest way)
cd ~
# or just:
cd

# go back to the previous folder
cd -

# combine shortcuts
cd ~/Documents/projects

the Linux folder structure

Bash

# see the whole tree from root
ls /

# your personal folder
ls /home/alice

# system config files
ls /etc

# system logs (needs sudo sometimes)
ls /var/log

# where programs are installed
ls /usr/bin

# temporary files (cleared on reboot)
ls /tmp

Files & Directories

Creating, copying, moving, and deleting files — these are the commands you'll reach for every single session. The dangerous one is rm. It has no recycle bin.

create files and folders

Bash

# create an empty file
touch notes.txt

# create multiple files at once
touch file1.txt file2.txt file3.txt

# create a folder
mkdir projects

# create nested folders in one step
# -p creates parent folders if they don't exist
mkdir -p projects/2024/january

# create a folder and go into it
mkdir my-app && cd my-app

copy and move files

Bash

# copy a file
cp notes.txt backup.txt

# copy to a different folder
cp notes.txt ~/Documents/

# copy a folder and everything inside it
# -r means recursive
cp -r projects/ projects-backup/

# move a file to a folder
mv notes.txt ~/Documents/

# rename a file
mv old-name.txt new-name.txt

# move and rename at the same time
mv notes.txt ~/Documents/my-notes.txt

delete files and folders

Bash

# delete a file
rm notes.txt

# delete multiple files
rm file1.txt file2.txt

# delete a folder and everything inside
rm -r projects/

# ask for confirmation before each delete
rm -ri projects/

# delete an empty folder only
rmdir empty-folder/

# safe habit: check what you're deleting first
ls projects/
# then delete
rm -r projects/

Never run rm -rf / or rm -rf ~/ — these delete your entire system or home folder permanently. There is no recovery.

tree — visualise folder structure

Bash

# install first if needed
sudo apt install tree

# show folder structure
tree

# limit to 2 levels deep
tree -L 2

# show hidden files too
tree -a

# show only folders, no files
tree -d

# show a specific folder
tree ~/Documents

Viewing & Editing Files

You don't need to open a file manager to read a file. These commands let you peek inside files, read logs, and make quick edits — all without leaving the terminal.

cat, less, head, tail — read files

Bash

# print the whole file
cat notes.txt

# show line numbers
cat -n notes.txt

# scroll through a long file
# press q to quit, / to search
less /var/log/syslog

# first 10 lines
head notes.txt

# first 20 lines
head -n 20 notes.txt

# last 10 lines
tail notes.txt

# watch a log file update live
# Ctrl+C to stop
tail -f /var/log/syslog

echo and redirection — write to files

Bash

# print text to the terminal
echo "Hello, Linux"

# write to a file (overwrites)
echo "Hello" > greetings.txt

# append to a file (keeps existing content)
echo "World" >> greetings.txt

# write multiple lines
echo "line one" > notes.txt
echo "line two" >> notes.txt

# write command output to a file
ls -l > file-list.txt

# append command output to a file
ls -la >> file-list.txt

Using > on an existing file deletes all its previous content instantly. Use >> if you want to add to it instead.

nano — beginner-friendly text editor

Bash

# open or create a file
nano notes.txt

# nano shows shortcuts at the bottom
# ^ means Ctrl key

# Ctrl+O  → save
# Ctrl+X  → exit
# Ctrl+W  → search
# Ctrl+K  → cut line
# Ctrl+U  → paste line
# Ctrl+G  → help

# open a file and jump to a line
nano +42 notes.txt

wc and sort — quick file analysis

Bash

# count lines, words, characters
wc notes.txt
# output: 12  45  230  notes.txt
#         lines words chars

# count lines only
wc -l notes.txt

# sort lines alphabetically
sort names.txt

# sort in reverse order
sort -r names.txt

# sort numerically
sort -n numbers.txt

# remove duplicate lines (input must be sorted)
sort names.txt | uniq

# count how many times each line appears
sort names.txt | uniq -c

Finding Things

find and grep are two of the most useful commands in Linux. find locates files by name or type. grep searches inside files for text. Together with the pipe, they're incredibly powerful.

find — locate files and folders

Bash

# find a file by name (case sensitive)
find /home -name "notes.txt"

# case insensitive name search
find /home -iname "notes.txt"

# find all .txt files
find /home -name "*.txt"

# find only folders
find /home -type d -name "projects"

# find only files
find /home -type f -name "*.log"

# find files larger than 100MB
find / -size +100M

# find files changed in the last 7 days
find /home -mtime -7

# find and delete matching files
find /tmp -name "*.tmp" -delete

grep — search inside files

Bash

# search for a word in a file
grep "error" logs.txt

# case insensitive
grep -i "error" logs.txt

# show line numbers
grep -n "error" logs.txt

# search all files in a folder
grep -r "TODO" ~/projects/

# case insensitive + recursive
grep -ri "password" ~/projects/

# show only filenames that match
grep -rl "TODO" ~/projects/

# show lines that do NOT match
grep -v "debug" logs.txt

# search for an exact whole word
grep -w "cat" animals.txt
# won't match "catch" or "scatter"

the pipe | — chain commands together

Bash

# count how many lines contain 'error'
grep -i "error" logs.txt | wc -l

# find .txt files then count them
find /home -name "*.txt" | wc -l

# list processes and search for one
ps aux | grep "nginx"

# list files, sort them, show top 5
ls -l | sort -k5 -n | tail -5

# search logs, remove duplicates
grep "ERROR" logs.txt | sort | uniq

# find large files and sort by size
du -h /var/log/* | sort -rh | head -10

File Permissions

Every file in Linux has an owner and a set of rules about who can read, write, or run it. Understanding permissions is what separates Linux beginners from people who actually feel comfortable in the terminal.

reading ls -l output

Bash

# show permissions for all files
ls -l

# example output:
# -rw-r--r-- 1 alice users  420 Jan 5 notes.txt
# drwxr-xr-x 2 alice users 4096 Jan 5 projects/

# breakdown of: -rw-r--r--
# -         = it's a file (d = directory)
# rw-       = owner can read + write
# r--       = group can only read
# r--       = others can only read

# breakdown of: drwxr-xr-x
# d         = it's a directory
# rwx       = owner can read, write, enter
# r-x       = group can read and enter
# r-x       = others can read and enter

chmod — change permissions

Bash

# symbolic method
# u=owner, g=group, o=others, a=all
# +=add, -=remove, ==set exactly

# add execute for owner
chmod u+x script.sh

# remove write for group
chmod g-w notes.txt

# set read-only for everyone
chmod a=r notes.txt

# numeric method (most common)
# 7 = rwx (4+2+1)
# 6 = rw- (4+2)
# 5 = r-x (4+1)
# 4 = r-- (4)

# owner=rwx, group=r-x, others=r-x
chmod 755 script.sh

# owner=rw-, group=r--, others=r--
chmod 644 notes.txt

# apply to a whole folder recursively
chmod -R 755 projects/

chown — change owner and group

Bash

# change owner of a file
sudo chown alice notes.txt

# change owner and group
sudo chown alice:developers notes.txt

# change only the group
sudo chgrp developers notes.txt

# change owner recursively for a folder
sudo chown -R alice:developers projects/

# check who owns a file
ls -l notes.txt
# output: -rw-r--r-- 1 alice developers ...
#                      ^^^^^  ^^^^^^^^^^
#                      owner  group

Users & Groups

Linux was built for multiple users from day one. Every file has an owner, every action has a user behind it. sudo is the command that gives you temporary admin power — use it carefully.

whoami, id, sudo — know who you are

Bash

# who am I logged in as?
whoami

# full user info: ID, groups
id

# run one command as admin
sudo apt update

# switch to another user
su alice

# switch to root (use carefully)
sudo su

# see who is currently logged in
who

# see login history
last

manage users and passwords

Bash

# create a new user (Ubuntu/Debian)
# asks for password and info interactively
sudo adduser alice

# create user (manual, less friendly)
sudo useradd -m alice

# set or change a password
sudo passwd alice

# delete a user (keeps home folder)
sudo deluser alice

# delete user and their home folder
sudo deluser --remove-home alice

# add user to a group (e.g. sudo group)
sudo usermod -aG sudo alice

# lock a user account
sudo usermod -L alice

# unlock a user account
sudo usermod -U alice

manage groups

Bash

# see which groups you belong to
groups

# see groups for another user
groups alice

# create a new group
sudo groupadd developers

# add a user to a group
sudo usermod -aG developers alice

# remove a user from a group
sudo gpasswd -d alice developers

# delete a group
sudo groupdel developers

# list all groups on the system
cat /etc/group

Processes

Every running program is a process. Linux gives each one a unique ID number called a PID. You can view, pause, and stop processes — including ones that have frozen and won't close.

ps and top — see what's running

Bash

# snapshot of all running processes
ps aux

# columns: USER  PID  %CPU  %MEM  COMMAND

# find a specific process
ps aux | grep nginx

# live view of processes
# press q to quit
top

# friendlier live view (install if needed)
sudo apt install htop
htop

# show process tree (parent → children)
pstree

kill — stop a process

Bash

# find the PID first
ps aux | grep firefox

# polite stop (process can clean up)
kill 1234

# force stop (immediate, no cleanup)
kill -9 1234

# stop all processes with a name
killall firefox

# stop by name (more flexible)
pkill firefox

# stop by name, force kill
pkill -9 firefox

background jobs — run without blocking

Bash

# run a command in the background
sleep 60 &
# prints: [1] 1234  (job number, PID)

# see all background jobs
jobs

# bring job 1 back to foreground
fg %1

# send current foreground job to background
# first pause it:
# Ctrl+Z
# then resume in background:
bg %1

# run a command that survives logout
nohup long-script.sh &

# check if it's still running
ps aux | grep long-script.sh

Disk & System Info

These commands tell you what's happening on your system. Running out of disk space is one of the most common causes of mysterious server failures — df will tell you in seconds.

df and du — disk usage

Bash

# disk space left on all partitions
df -h

# example output:
# Filesystem  Size  Used  Avail  Use%  Mounted on
# /dev/sda1   50G   22G   26G    46%   /

# size of a folder
du -h ~/Documents

# size of every item in a folder
du -h ~/Documents/*

# total size only
du -sh ~/Documents

# find the 10 biggest folders
du -h /var/* | sort -rh | head -10

free, uname, uptime — system info

Bash

# RAM usage
free -h
# output: total  used  free  available

# kernel and OS info
uname -a
# shows: kernel version, hostname, architecture

# just the kernel version
uname -r

# how long the system has been running
uptime
# output: 14:32  up 3 days, 2:15, 2 users

# your machine's hostname
hostname

# full system info summary
uname -a

# OS name and version
cat /etc/os-release

lsblk and mount — storage devices

Bash

# list all storage devices and partitions
lsblk

# example output:
# NAME   SIZE  TYPE  MOUNTPOINT
# sda    500G  disk
# ├─sda1 499G  part  /
# └─sda2   1G  part  [SWAP]
# sdb     32G  disk
# └─sdb1  32G  part  /media/usb

# see currently mounted devices
mount | grep "^/dev"

# mount a USB drive
sudo mount /dev/sdb1 /mnt/usb

# unmount safely before unplugging
sudo umount /mnt/usb

Networking

Linux networking commands let you check your connection, download files, connect to remote servers, and diagnose problems. These come up constantly once you start working with servers.

ping, ip, curl — connection basics

Bash

# test if a server is reachable
ping google.com
# Ctrl+C to stop

# ping exactly 4 times
ping -c 4 google.com

# show your IP addresses
ip addr show

# shorter version
ip a

# older command (may need installing)
ifconfig

# download a file
curl -O https://example.com/file.zip

# see response headers only
curl -I https://example.com

# download with wget
wget https://example.com/file.zip

ssh — connect to a remote server

Bash

# connect to a remote server
ssh alice@192.168.1.100

# connect with a custom port
ssh -p 2222 alice@192.168.1.100

# connect using an SSH key file
ssh -i ~/.ssh/mykey.pem alice@server.com

# generate an SSH key pair
ssh-keygen -t ed25519 -C "[email protected]"

# copy your public key to a server
# (lets you log in without a password)
ssh-copy-id alice@192.168.1.100

# run one command on remote server
ssh alice@server.com "ls /var/www"

scp and rsync — copy files over SSH

Bash

# copy file TO a remote server
scp notes.txt alice@server.com:/home/alice/

# copy file FROM a remote server
scp alice@server.com:/home/alice/notes.txt .

# copy a whole folder
scp -r projects/ alice@server.com:/home/alice/

# rsync — smarter: only copies what changed
rsync -av projects/ alice@server.com:/home/alice/projects/

# rsync flags:
# -a = archive (preserves permissions, dates)
# -v = verbose (show what's being copied)
# -z = compress during transfer
# --delete = remove files on destination
#            that no longer exist on source

ss and netstat — active connections

Bash

# show all listening ports (modern)
ss -tuln

# columns: protocol, local address, port

# show with process names
ss -tulnp

# older command (same purpose)
netstat -tuln

# check if a specific port is in use
ss -tuln | grep :80

# show established connections
ss -tn state established

Package Management

Package managers install, update, and remove software for you — no hunting for installers. The commands are different depending on which Linux distribution you use.

apt — Ubuntu and Debian

Bash

# refresh the package list
sudo apt update

# install available upgrades
sudo apt upgrade

# install a package
sudo apt install nginx

# install multiple packages
sudo apt install git curl wget

# remove a package
sudo apt remove nginx

# remove package + its config files
sudo apt purge nginx

# remove unused dependencies
sudo apt autoremove

# search for a package
apt search nginx

# show package details
apt show nginx

dnf and yum — RHEL, Fedora, CentOS

Bash

# install a package (Fedora/RHEL/CentOS)
sudo dnf install nginx

# update all packages
sudo dnf update

# remove a package
sudo dnf remove nginx

# search for a package
dnf search nginx

# show package info
dnf info nginx

# list installed packages
dnf list installed

# older systems: replace dnf with yum
sudo yum install nginx
sudo yum update
sudo yum remove nginx

snap and flatpak — universal packages

Bash

# snap — works on most distros
# install a snap package
sudo snap install code --classic

# list installed snaps
snap list

# update all snaps
sudo snap refresh

# remove a snap
sudo snap remove code

# flatpak — another universal format
# install flatpak support first
sudo apt install flatpak

# add the main app store
flatpak remote-add --if-not-exists flathub \
  https://flathub.org/repo/flathub.flatpakrepo

# install an app
flatpak install flathub org.gimp.GIMP

# run a flatpak app
flatpak run org.gimp.GIMP

Archives & Compression

tar is the main tool for bundling files together on Linux. gzip and zip handle compression. You'll use these constantly for backups, deployments, and downloading projects.

tar — bundle and compress files

Bash

# create a compressed archive
tar -czf backup.tar.gz projects/

# extract an archive
tar -xzf backup.tar.gz

# extract to a specific folder
tar -xzf backup.tar.gz -C /home/alice/

# list contents without extracting
tar -tvf backup.tar.gz

# create archive without compression
tar -cf backup.tar projects/

# extract .tar.bz2 (uses bzip2 instead)
tar -xjf backup.tar.bz2

gzip, zip, unzip

Bash

# gzip: compress a single file
# (original file is replaced by .gz)
gzip notes.txt
# creates: notes.txt.gz

# decompress
gunzip notes.txt.gz

# gzip without removing original
gzip -k notes.txt

# zip: create a .zip archive
zip archive.zip file1.txt file2.txt

# zip a whole folder
zip -r archive.zip projects/

# unzip
unzip archive.zip

# unzip to a specific folder
unzip archive.zip -d /home/alice/

# list contents of a zip
unzip -l archive.zip

Shell & Environment

The shell has its own settings — variables, shortcuts, and a config file that runs every time you open a terminal. Learning this layer makes everything else faster.

variables and environment

Bash

# create a variable (local to this shell)
NAME="Alice"

# use it with $
echo $NAME

# export: available to child processes
export NAME="Alice"

# see all environment variables
env

# see one specific variable
echo $HOME
echo $PATH
printenv HOME

# add a folder to PATH
# (so you can run programs in that folder)
export PATH=$PATH:/home/alice/scripts

# see your current shell
echo $SHELL

.bashrc — your shell config file

Bash

# open your shell config
nano ~/.bashrc

# add aliases (shortcuts)
alias ll='ls -la'
alias ..='cd ..'
alias gs='git status'

# add a permanent export
export EDITOR=nano
export PATH=$PATH:/home/alice/scripts

# apply changes without restarting terminal
source ~/.bashrc
# or shorter:
. ~/.bashrc

# for Zsh users
nano ~/.zshrc
source ~/.zshrc

history — recall past commands

Bash

# show all past commands
history

# show last 20 commands
history 20

# search history interactively
# Ctrl+R then type to search
# Ctrl+R again for next match
# Enter to run, Esc to cancel

# run the last command again
!!

# run command number 42 from history
!42

# run the last command starting with 'git'
!git

# clear history
history -c

keyboard shortcuts — move faster in the terminal

Bash

# autocomplete
# type part of a name, then press Tab
ls Doc<Tab>
# completes to: ls Documents/

# press Tab twice to see all matches
ls D<Tab><Tab>
# shows: Desktop/  Documents/  Downloads/

# cancel current command
# Ctrl+C

# clear the screen
# Ctrl+L

# jump to start / end of line
# Ctrl+A  /  Ctrl+E

# delete from cursor to start of line
# Ctrl+U

# delete from cursor to end of line
# Ctrl+K

# paste what you just deleted
# Ctrl+Y

# close the terminal / exit shell
# Ctrl+D

Tips & Good Habits

These habits are the ones that keep you out of trouble. Some of them are shortcuts. Others are the kind of thing you only learn after making a painful mistake — so you don't have to.

check before you destroy

Bash

# check what a wildcard matches BEFORE deleting
echo *.log
# shows: error.log  access.log  debug.log

# then delete confidently
rm *.log

# ask for confirmation on each file
rm -i *.log

# preview a find + delete without actually deleting
find /tmp -name "*.tmp" -print
# check the output, then delete:
find /tmp -name "*.tmp" -delete

# before removing a folder
ls -la projects/old-stuff/
# satisfied? then:
rm -r projects/old-stuff/

rm has no recycle bin. rm -rf on the wrong path can delete your entire project or system. Always verify the path first.

never run these commands

Bash

# ❌ NEVER run these

# deletes everything on the system
rm -rf /

# deletes your entire home folder
rm -rf ~/

# crashes system with infinite processes
# (fork bomb)
:(){ :|:& };:

# overwrites entire hard drive
dd if=/dev/random of=/dev/sda

If you find any of these commands online with no explanation of what they do, do not run them. They are system-destroying commands sometimes shared as jokes.

use sudo only when needed

Bash

# these need sudo
sudo apt install nginx
sudo systemctl restart nginx
sudo nano /etc/nginx/nginx.conf
sudo chown root:root /etc/config

# these do NOT need sudo
ls ~/Documents
cd /var/log
grep "error" ~/app/logs/app.log
cp myfile.txt ~/backup/

# check if a command failed because of permissions
# look for: Permission denied
ls /root
# output: ls: cannot open '/root': Permission denied
# then use sudo:
sudo ls /root

chaining commands — do more in one line

Bash

# && — second runs only if first succeeds
mkdir my-app && cd my-app

# useful: update then upgrade, only if update worked
sudo apt update && sudo apt upgrade

# || — second runs only if first fails
cd projects || mkdir projects

# ; — always run both (success or fail)
echo "Starting..."; npm install; echo "Done"

# combine all three
sudo apt update && sudo apt upgrade -y || echo "Update failed"

handy one-liners worth bookmarking

Bash

# find where a program is installed
which nginx
which python3

# see all active aliases
alias

# current date and time
date

# calendar for this month
cal

# how long a command takes to run
time npm install

# repeat a command every 2 seconds
# (like a live dashboard)
watch -n 2 df -h

# see the last 10 commands with timestamps
HISTTIMEFORMAT="%F %T " history 10

# quickly make a backup copy of a file
cp nginx.conf nginx.conf.bak

# download and run a script in one line
# (only from sources you trust)
curl -fsSL https://example.com/install.sh | bash
Was this helpful?

No login required to share feedback

More Cheatsheets

Keep your reference handy

Explore more zero-to-hero cheatsheets for the tools you use daily.