Garmr
Menu
Cheatsheets
linux logo

Linux

September 30, 2026 · 8 min read

On this page

🐧 Native Linux Commands

Available out of the box on virtually every Linux system.

pwd

Shows the current directory

pwd (Print Working Directory)
  -P            show real path (resolves symlinks)
  e.g.          pwd

ls

Lists files in a directory

ls (LiSt)
  -l            long format (permissions, owner, size, date)
  -a            include hidden files (starting with .)
  -h            human-readable sizes (with -l)
  -t            sort by modification time
  -R            list subdirectories recursively
  e.g.          ls -lah ~/Downloads

cd

Moves to another directory

cd <dir> (Change Directory)
  ~             home directory
  ..            parent directory
  -             previous directory
  e.g.          cd ../projects

📄 Files & Directories

touch

Creates an empty file / updates its timestamp

touch <file> ("touches" the file, marking it as modified)
  -c            don't create the file if it doesn't exist
  e.g.          touch notes.txt

mkdir

Creates a directory

mkdir <dir> (MaKe DIRectory)
  -p            create parent dirs as needed, no error if exists
  -v            print each directory created
  e.g.          mkdir -p src/app/utils

cp

Copies files and directories

cp <src> <dst> (CoPy)
  -r            copy directories recursively
  -i            ask before overwriting
  -v            show what is being copied
  e.g.          cp -rv photos/ backup/

mv

Moves or renames files

mv <src> <dst> (MoVe)
  -i            ask before overwriting
  -n            never overwrite
  e.g.          mv old.txt new.txt

rm

Deletes files and directories

rm <file> (ReMove)
  -r            delete directories and their contents
  -f            force, no prompts (⚠️ careful)
  -i            ask before each deletion
  e.g.          rm -ri old_project/

rmdir

Deletes an empty directory

rmdir <dir> (ReMove DIRectory)
  -p            also remove empty parent directories
  e.g.          rmdir empty_folder

ln

Creates links to files

ln <target> <link> (LiNk)
  -s            symbolic (soft) link
  -f            replace existing link
  e.g.          ln -s /opt/app/bin/app ~/bin/app

👀 Viewing Files

cat

Prints a file's contents

cat <file> (conCATenate)
  -n            number lines
  e.g.          cat -n script.sh
                cat part1.txt part2.txt > full.txt

less

Scrolls through a file

less <file> ("less is more", an improved version of `more`)
  /text         search forward
  n / N         next / previous match
  g / G         go to start / end
  q             quit
  e.g.          less /var/log/syslog

head

Shows the beginning of a file

head <file> (the HEAD of the file)
  -n <N>        show first N lines (default 10)
  e.g.          head -n 5 data.csv

tail

Shows the end of a file

tail <file> (the TAIL of the file)
  -n <N>        show last N lines (default 10)
  -f            follow file as it grows
  e.g.          tail -f /var/log/syslog

wc

Counts lines, words and bytes

wc <file> (Word Count)
  -l            lines only
  -w            words only
  -c            bytes only
  e.g.          wc -l access.log

🔍 Searching

find

Searches for files and directories

find <path>
  -name         match name (use quotes for wildcards)
  -iname        case-insensitive name match
  -type f|d     files only | directories only
  -size +N      larger than N (e.g. +100M)
  -mtime -N     modified in the last N days
  e.g.          find . -type f -name "*.log" -mtime -7

grep

Searches text inside files

grep <pattern> <file> (Global Regular Expression Print)
  -i            case-insensitive
  -r            search directories recursively
  -n            show line numbers
  -v            invert (lines that DON'T match)
  -l            show only filenames with matches
  -c            count matches
  e.g.          grep -rin "todo" src/

which

Shows where a command's program lives

which <cmd>
  -a            show all matches in PATH
  e.g.          which python3

🔐 Permissions & Ownership

chmod

Changes file permissions

chmod <mode> <file> (CHange MODe)
  -R            apply recursively
  +x / -x       add / remove execute
  u g o a       user, group, others, all
  e.g.          chmod +x deploy.sh
                chmod 644 index.html
                chmod -R u+rw,go-w shared/

Permission numbers: r=4 w=2 x=1 → 7=rwx 6=rw- 5=r-x 4=r--, in order owner / group / others (so 755 = rwxr-xr-x).

chown

Changes file owner and group

chown <user>:<group> <file> (CHange OWNer)
  -R            apply recursively
  e.g.          sudo chown -R www-data:www-data /var/www

sudo

Runs a command as administrator

sudo <cmd> (SuperUser DO)
  -i            open a root shell
  -u <user>     run as another user
  e.g.          sudo apt update

⚙️ Processes

ps

Lists running processes

ps (Process Status)
  aux           all processes, all users, detailed
  -ef           all processes, full format
  e.g.          ps aux | grep nginx

top

Shows a live process monitor

top (TOP resource-consuming processes)
  P / M         sort by CPU / memory
  k             kill a process
  q             quit
  e.g.          top

kill

Stops a process by ID

kill <PID>
  -15           graceful stop (default, SIGTERM)
  -9            force kill (SIGKILL)
  -l            list all signals
  e.g.          kill -9 4821

pkill

Stops processes by name

pkill <name> (Process KILL)
  -9            force kill
  -u <user>     only that user's processes
  e.g.          pkill firefox

Job control

Manages commands in the background

<cmd> &         run in background
jobs            list background jobs
fg %N           bring job N to foreground
bg %N           resume job N in background
Ctrl+C          stop current command
Ctrl+Z          suspend current command
  e.g.          ./long_script.sh &

🖥️ System Information

uname

Shows system and kernel info

uname (Unix NAME)
  -a            everything (kernel, arch, hostname)
  -r            kernel version only
  -m            hardware architecture
  e.g.          uname -a

df

Shows free disk space

df (Disk Free)
  -h            human-readable
  -T            show filesystem type
  e.g.          df -h

du

Shows space used by files/directories

du <path> (Disk Usage)
  -s            summary (total only)
  -h            human-readable
  --max-depth=N limit how deep it goes
  e.g.          du -sh ~/Videos

free

Shows memory usage

free
  -h            human-readable
  e.g.          free -h

whoami

Shows current user

whoami (Who Am I)

uptime

Shows time since boot and system load

uptime (how long the system has been UP)
  -p            pretty format
  e.g.          uptime -p

🌐 Networking

ip

Shows and manages network interfaces

ip (Internet Protocol)
  a             show addresses
  r             show routes
  link          show interfaces
  e.g.          ip a

ping

Tests connectivity to a host

ping <host> (named after the sonar "ping" sound)
  -c <N>        send only N packets
  -i <sec>      interval between packets
  e.g.          ping -c 4 google.com

ssh

Logs in to a remote machine

ssh <user>@<host> (Secure SHell)
  -p <port>     custom port
  -i <key>      use specific private key
  e.g.          ssh -i ~/.ssh/id_ed25519 -p 2222 me@server

scp

Copies files over SSH

scp <src> <dst> (Secure CoPy)
  -r            copy directories
  -P <port>     custom port (capital P!)
  e.g.          scp -r site/ me@server:/var/www/

ss

Shows network connections and ports

ss (Socket Statistics)
  -t / -u       TCP / UDP
  -l            listening only
  -p            show process
  -n            numeric (don't resolve names)
  e.g.          ss -tulpn

📦 Archives & Compression

tar

Bundles and extracts archives

tar (Tape ARchive)
  -c            create archive
  -x            extract archive
  -t            list contents
  -z            gzip compression (.tar.gz)
  -v            verbose
  -f <file>     archive filename (put last)
  -C <dir>      extract into directory
  e.g.          tar -czvf backup.tar.gz docs/
                tar -xzvf backup.tar.gz -C /tmp

🔀 Redirection & Pipes

Operators

Sends output to files or other commands

>               write output to file (overwrite)
>>              append output to file
2>              redirect errors
&>              redirect output + errors
|               pipe output into next command
&&              run next only if previous succeeded
;               run next regardless
  e.g.          ls -l > list.txt
                make 2> errors.log
                cat access.log | grep 404 | wc -l

🆘 Help & Shortcuts

man

Opens a command's full manual

man <cmd> (MANual)
  /text         search
  q             quit
  e.g.          man tar

history

Shows previous commands

history
  !N            rerun command number N
  !!            rerun last command
  -c            clear history
  e.g.          sudo !!

alias

Creates a command shortcut

alias <name>='<cmd>'
  e.g.          alias ll='ls -lah'
                unalias ll

Keyboard shortcuts

Helps you work faster in the terminal

Tab             autocomplete
Ctrl+R          search history
Ctrl+L          clear screen
Ctrl+A / E      jump to start / end of line
Ctrl+U          delete to start of line
Ctrl+D          exit the shell

🧰 Extra Tools & Package Managers

Very common, but may need to be installed or only exist on certain distros.

⚙️ Processes

htop

Shows a friendlier, colorful live process monitor

htop (Hisham's TOP, named after its author)
  F3            search
  F6            choose sort column
  F9            kill selected process
  F10 / q       quit

🌐 Networking

curl

Makes HTTP requests

curl <url> (Client URL)
  -O            save with remote filename
  -o <file>     save with a custom filename
  -L            follow redirects
  -I            show headers only
  -X <method>   set method (POST, PUT...)
  e.g.          curl -LO https://example.com/file.zip

wget

Downloads files

wget <url> (Web GET)
  -c            resume interrupted download
  -O <file>     save with a custom filename
  e.g.          wget -c https://example.com/big.iso

📦 Archives & Compression

zip

Creates a zip archive

zip <out.zip> <files>
  -r            include directories
  e.g.          zip -r site.zip site/

unzip

Extracts a zip archive

unzip <file.zip>
  -d <dir>      extract into directory
  -l            list contents
  e.g.          unzip site.zip -d ~/site

🧩 Package Management

apt

Package manager for Debian / Ubuntu

apt (Advanced Package Tool)
  update        refresh package list
  upgrade       upgrade installed packages
  install       install a package
  remove        remove a package
  search        search for a package
  e.g.          sudo apt update && sudo apt install git

dnf

Package manager for Fedora / RHEL

dnf (DaNdiFied yum, successor of yum)
  check-update  refresh and list updates
  upgrade       upgrade installed packages
  install       install a package
  remove        remove a package
  search        search for a package
  e.g.          sudo dnf install git

pacman

Package manager for Arch

pacman (PACkage MANager)
  -Syu          refresh and upgrade everything
  -S            install a package
  -R            remove a package
  -Ss           search for a package
  e.g.          sudo pacman -S git