Linux commands cheat sheet

Everyday Linux commands for Ubuntu, Debian, Fedora and Arch: updating packages, managing systemd services, checking resources, processes, permissions and the firewall.

25 commands

Update everything (Ubuntu/Debian)

LinuxAdmin

Refreshes package lists and installs all available updates.

sudo apt update && sudo apt upgrade -y

Update everything (Fedora)

LinuxAdmin

Refreshes metadata and upgrades all packages.

sudo dnf upgrade --refresh

Update everything (Arch)

LinuxAdmin

Syncs the package database and upgrades the system.

sudo pacman -Syu

Remove unused packages

LinuxAdmin

Deletes packages nothing depends on and clears the download cache.

sudo apt autoremove -y && sudo apt clean

Free disk space

LinuxmacOS

Disk usage of every mounted drive in human-readable sizes.

df -h

Biggest folders here

LinuxmacOS

Size of each item in the current folder, smallest to largest.

du -sh * | sort -h

Memory usage

Linux

Used, free and available RAM and swap.

free -h

Top memory-hungry processes

Linux

The ten processes using the most memory.

ps aux --sort=-%mem | head -n 10

Stop a process by PID

LinuxmacOSCareful

Asks the process to exit. If it ignores you, use kill -9 to force it.

kill

Stop processes by name

LinuxmacOSCareful

Stops every process whose command line matches.

pkill -f

Matches broadly; check with pgrep -fl first.

Check a service

Linux

Shows whether a service is running and its latest log lines.

systemctl status

Restart a service

LinuxAdmin

Stops and starts the service.

sudo systemctl restart

Start a service now and on boot

LinuxAdmin

Enables the service at boot and starts it immediately.

sudo systemctl enable --now

Follow a service’s logs

Linux

Streams new log lines as they arrive. Ctrl+C to stop.

journalctl -u -f

Which distro and version

Linux

Name, version and ID of the Linux distribution.

cat /etc/os-release

Kernel version

LinuxmacOS

Kernel name, version and architecture.

uname -a

Make a script executable

LinuxmacOS

Lets you run it with ./script.sh.

chmod +x

Take ownership of a folder

LinuxAdminCareful

Fixes "permission denied" on files created by root.

sudo chown -R $USER:$USER

Give a user sudo rights

LinuxAdminCareful

Adds the user to the sudo group (wheel on Fedora/Arch). They need to log in again.

sudo usermod -aG sudo

Listening ports and their programs

LinuxAdmin

Every open TCP/UDP port with the process that owns it.

sudo ss -tulpn

Open a port in the firewall

LinuxAdminCareful

Allows incoming traffic on a port (Ubuntu’s ufw). Enable the firewall with sudo ufw enable.

sudo ufw allow /tcp

Always allow SSH (22) before enabling ufw on a remote server, or you’ll lock yourself out.

Edit scheduled jobs

LinuxmacOS

Opens your cron table. Each line is: minute hour day month weekday command.

crontab -e

Re-run a command every few seconds

Linux

Refreshes the output on screen. Ctrl+C to stop.

watch -n

Copy a file to the clipboard

Linux

For Wayland desktops. On X11 use: xclip -selection clipboard < file.

wl-copy <

CPU details

Linux

Model, cores, threads and cache sizes.

lscpu

Every command copies as plain, clean text: no curly quotes, no long dashes, no invisible characters.

Related guides