Linux Command Cheat Sheet

Trending Posts

Categories

Blog Tags

    Linux Command Cheat Sheet
    LINUX ADMIN MEGA REFERENCE

    Linux Command
    Cheat Sheet

    A massive searchable, copy-ready reference for Linux students, technicians, homelab users, and sysadmins.

    382 commands
    27 sections
    1 standalone HTML file
    ⚠ Admin warning: Commands marked with ⚠ can delete data, overwrite disks, or make major system changes. Verify device names and paths before running them.
    cat file.txt

    Print a file

    tac file.txt

    Print lines in reverse order

    less file.txt

    View a file page by page

    more file.txt

    Simple paged file viewer

    head file.txt

    Show the first 10 lines

    head -n 25 file.txt

    Show the first 25 lines

    tail file.txt

    Show the last 10 lines

    tail -f /var/log/syslog

    Follow a growing log file

    nano file.txt

    Edit with Nano

    vim file.txt

    Edit with Vim

    wc -l file.txt

    Count lines

    wc -w file.txt

    Count words

    nl file.txt

    Show line numbers

    column -t file.txt

    Align whitespace-separated columns

    strings binaryfile

    Extract printable strings from a binary

    xxd file

    Hex dump a file

    grep 'text' file.txt

    Search for text

    grep -i 'text' file.txt

    Case-insensitive search

    grep -R 'text' /path

    Recursive search

    grep -n 'text' file.txt

    Show matching line numbers

    grep -v 'text' file.txt

    Show nonmatching lines

    grep -E 'cat

    dog' file.txt|Extended regex search

    cut -d: -f1 /etc/passwd

    Extract the first colon-delimited field

    sort file.txt

    Sort lines alphabetically

    sort -n numbers.txt

    Sort numerically

    uniq file.txt

    Remove adjacent duplicates

    sort file.txt

    uniq -c|Count repeated lines

    tr 'a-z' 'A-Z' < file.txt

    Convert lowercase to uppercase

    sed 's/old/new/g' file.txt

    Replace text in output

    sed -i 's/old/new/g' file.txt

    Replace text in place

    awk '{print $1}' file.txt

    Print the first field

    awk -F: '{print $1}' /etc/passwd

    Print the first colon-delimited field

    paste file1 file2

    Merge files side by side

    comm file1 file2

    Compare two sorted files

    diff -u old.txt new.txt

    Show a unified diff

    xargs -n1 echo < file.txt

    Build command arguments from stdin

    ls -l

    Show Unix permissions and ownership

    chmod 644 file.txt

    Set rw-r–r–

    chmod 755 script.sh

    Set rwxr-xr-x

    chmod +x script.sh

    Add execute permission

    chmod -R 750 directory

    Change permissions recursively

    chown user file.txt

    Change owner

    chown user:group file.txt

    Change owner and group

    chown -R user:group directory

    Change ownership recursively

    chgrp group file.txt

    Change group ownership

    umask

    Show current creation mask

    umask 022

    Set a common creation mask

    getfacl file.txt

    Display ACL permissions

    setfacl -m u:alice:rw file.txt

    Grant ACL permissions to a user

    whoami

    Print current username

    id

    Show UID GID and groups

    id username

    Show another user's identity information

    who

    Show logged-in users

    w

    Show logged-in users and activity

    last

    Show login history

    users

    Print logged-in usernames

    sudo command

    Run a command with elevated privileges

    sudo -i

    Open a root login shell

    su - username

    Switch to another user

    useradd -m username

    Create a user and home directory

    adduser username

    Interactive user creation on Debian or Ubuntu

    passwd username

    Set or change a password

    usermod -aG sudo username

    Add a user to sudo group

    usermod -aG group username

    Add a user to a supplementary group

    groups username

    Show group memberships

    groupadd groupname

    Create a group

    userdel -r username

    Delete a user and home directory ⚠

    getent passwd username

    Query account information

    ps

    Show processes in the current shell

    ps aux

    Show all processes

    ps -ef

    Show all processes in full format

    top

    Interactive process monitor

    htop

    Enhanced interactive process monitor

    pgrep nginx

    Find PIDs by name

    pidof sshd

    Print PID of a program

    kill PID

    Send SIGTERM

    kill -9 PID

    Force-kill with SIGKILL

    pkill nginx

    Kill processes by name

    killall processname

    Kill all matching processes

    nice -n 10 command

    Start with adjusted priority

    renice 5 -p PID

    Change priority of a running process

    jobs

    List shell jobs

    command &

    Run a command in the background

    fg %1

    Bring job 1 to foreground

    bg %1

    Resume job 1 in background

    nohup command &

    Keep a command running after logout

    watch -n 2 command

    Repeat a command every 2 seconds

    time command

    Measure execution time

    uname -a

    Show kernel and architecture information

    uname -r

    Show kernel version

    hostname

    Show hostname

    hostnamectl

    Show hostname and system metadata

    cat /etc/os-release

    Show Linux distribution information

    lsb_release -a

    Show distribution details if installed

    uptime

    Show uptime and load averages

    date

    Show current date and time

    timedatectl

    Show time configuration

    cal

    Display a calendar

    arch

    Show machine architecture

    lscpu

    Show CPU information

    free -h

    Show memory usage

    vmstat

    Show memory CPU and process statistics

    lsmem

    Show memory block information

    dmidecode

    Show SMBIOS hardware information

    lspci

    List PCI devices

    lsusb

    List USB devices

    sensors

    Show hardware temperatures if configured

    df -h

    Show filesystem disk usage

    df -i

    Show inode usage

    du -sh directory

    Show total size of a directory

    du -h --max-depth=1

    Show one-level directory sizes

    lsblk

    List block devices

    lsblk -f

    Show filesystems on block devices

    blkid

    Show UUIDs and filesystem types

    fdisk -l

    List partition tables

    parted -l

    List partitions with GNU Parted

    mount

    Show mounted filesystems

    mount /dev/sdb1 /mnt

    Mount a filesystem

    umount /mnt

    Unmount a filesystem

    findmnt

    Show mounted filesystems as a tree

    fsck /dev/sdXN

    Check or repair an unmounted filesystem ⚠

    mkfs.ext4 /dev/sdXN

    Create an ext4 filesystem and erase existing filesystem data ⚠

    mkswap /dev/sdXN

    Create swap space ⚠

    swapon --show

    Show active swap

    swapon /swapfile

    Enable swap

    swapoff /swapfile

    Disable swap

    sync

    Flush filesystem buffers

    ip addr

    Show interfaces and IP addresses

    ip -br addr

    Brief interface and address view

    ip link

    Show link state

    ip route

    Show routing table

    ip neigh

    Show neighbor or ARP table

    hostname -I

    Show host IP addresses

    ping 8.8.8.8

    Test IP connectivity

    ping -c 4 example.com

    Send four ICMP requests

    traceroute example.com

    Trace the network path

    tracepath example.com

    Trace path without raw-socket privileges

    ss -tulpn

    Show listening TCP and UDP sockets

    ss -tan

    Show TCP connections

    netstat -tulpn

    Legacy socket and listener view

    curl https://example.com

    Fetch a URL

    curl -I https://example.com

    Fetch HTTP headers

    curl -O https://example.com/file.iso

    Download using the remote filename

    wget https://example.com/file.iso

    Download a file

    dig example.com

    Query DNS

    dig +short example.com

    Concise DNS query

    nslookup example.com

    Simple DNS lookup

    host example.com

    DNS lookup with host

    resolvectl status

    Show systemd-resolved status

    nmcli device status

    Show NetworkManager devices

    nmcli connection show

    List NetworkManager connections

    ethtool eth0

    Show Ethernet link details

    ssh user@server

    Connect to a remote host

    ssh -p 2222 user@server

    SSH on a custom port

    ssh-keygen -t ed25519

    Generate an Ed25519 SSH key

    ssh-copy-id user@server

    Install your public key remotely

    scp file user@server:/path/

    Copy a file to a remote host

    scp user@server:/path/file .

    Copy a remote file locally

    scp -r directory user@server:/path/

    Copy a directory over SSH

    sftp user@server

    Open an SFTP session

    rsync -av source/ dest/

    Synchronize directories locally

    rsync -avz source/ user@server:/path/

    Synchronize to a remote host

    ssh -L 8080:localhost:80 user@server

    Create a local SSH port forward

    systemctl status ssh

    Show service status

    systemctl start ssh

    Start a service

    systemctl stop ssh

    Stop a service

    systemctl restart ssh

    Restart a service

    systemctl reload nginx

    Reload service configuration if supported

    systemctl enable ssh

    Enable a service at boot

    systemctl disable ssh

    Disable a service at boot

    systemctl enable --now ssh

    Enable and start immediately

    systemctl list-units --type=service

    List loaded services

    systemctl list-unit-files

    List installed unit files

    systemctl daemon-reload

    Reload systemd unit definitions

    systemctl is-active ssh

    Check whether a service is active

    systemctl is-enabled ssh

    Check whether a service starts at boot

    systemctl reboot

    Reboot the system

    systemctl poweroff

    Power off the system

    journalctl

    View the systemd journal

    journalctl -b

    Show logs from current boot

    journalctl -b -1

    Show logs from previous boot

    journalctl -u ssh

    Show logs for a service

    journalctl -u nginx -f

    Follow service logs

    journalctl -p err

    Show error-priority messages

    journalctl --since '1 hour ago'

    Show recent logs

    dmesg

    Show kernel messages

    dmesg -T

    Show kernel messages with readable timestamps

    tail -f /var/log/syslog

    Follow Ubuntu or Debian system log

    tail -f /var/log/messages

    Follow common RHEL-family system log

    lastb

    Show failed login attempts where supported

    sudo apt update

    Refresh package indexes

    sudo apt upgrade

    Upgrade installed packages

    sudo apt full-upgrade

    Upgrade allowing dependency changes

    sudo apt install package

    Install a package

    sudo apt remove package

    Remove a package

    sudo apt purge package

    Remove package and configuration

    sudo apt autoremove

    Remove unused dependencies

    apt search keyword

    Search packages

    apt show package

    Show package information

    dpkg -l

    List installed Debian packages

    dpkg -L package

    List files installed by a package

    sudo dpkg -i file.deb

    Install a local DEB package

    sudo dnf check-update

    Check for updates

    sudo dnf upgrade

    Upgrade installed packages

    sudo dnf install package

    Install a package

    sudo dnf remove package

    Remove a package

    dnf search keyword

    Search packages

    dnf info package

    Show package information

    rpm -qa

    List installed RPM packages

    rpm -ql package

    List files from an installed RPM package

    sudo pacman -Syu

    Update repositories and upgrade the system

    sudo pacman -S package

    Install a package

    sudo pacman -R package

    Remove a package

    sudo pacman -Rs package

    Remove a package and unneeded dependencies

    pacman -Ss keyword

    Search repositories

    pacman -Qi package

    Show installed package information

    tar -czf archive.tar.gz directory/

    Create a gzip-compressed tar archive

    tar -xzf archive.tar.gz

    Extract a tar.gz archive

    tar -cJf archive.tar.xz directory/

    Create an xz-compressed tar archive

    tar -xJf archive.tar.xz

    Extract a tar.xz archive

    tar -tf archive.tar.gz

    List archive contents

    zip -r archive.zip directory/

    Create a ZIP archive

    unzip archive.zip

    Extract a ZIP archive

    gzip file

    Compress to file.gz

    gunzip file.gz

    Decompress gzip

    xz file

    Compress with xz

    unxz file.xz

    Decompress xz

    7z a archive.7z directory/

    Create a 7-Zip archive

    7z x archive.7z

    Extract a 7-Zip archive

    echo $PATH

    Print executable search path

    env

    Show environment variables

    printenv

    Print environment variables

    export VAR=value

    Set an environment variable

    unset VAR

    Remove an environment variable

    history

    Show shell history

    history

    grep ssh|Search shell history

    !!

    Run the previous command again

    !123

    Run history entry 123

    alias ll='ls -lah'

    Create a temporary alias

    unalias ll

    Remove an alias

    which python3

    Locate an executable

    command -v python3

    Portable command lookup

    type cd

    Describe how a command name is interpreted

    source ~/.bashrc

    Reload Bash configuration

    bash script.sh

    Run a Bash script

    ./script.sh

    Run an executable script from current directory

    command > file.txt

    Redirect stdout and overwrite

    command >> file.txt

    Append stdout

    command 2> errors.txt

    Redirect stderr

    command > out.txt 2>&1

    Redirect stdout and stderr together

    command1

    command2|Pipe output into another command

    command

    tee file.txt|Display and save output

    command

    tee -a file.txt|Display and append output

    command < input.txt

    Use a file as stdin

    cmd1 && cmd2

    Run cmd2 only if cmd1 succeeds

    cmd1

    | cmd2|Run cmd2 only if cmd1 fails

    cmd1 ; cmd2

    Run sequentially regardless of status

    dd if=input.img of=output.img bs=4M status=progress

    Copy an image or file with progress

    dd if=/dev/sdX of=disk.img bs=4M status=progress

    Create a raw disk image ⚠

    dd if=disk.img of=/dev/sdX bs=4M status=progress

    Write a raw image to a disk ⚠

    crontab -e

    Edit current user's cron jobs

    crontab -l

    List current user's cron jobs

    sudo crontab -e

    Edit root's cron jobs

    at 17:00

    Schedule a one-time job for 5 PM

    atq

    List queued at jobs

    atrm JOBID

    Remove a queued at job

    systemctl list-timers

    List systemd timers

    sudo ufw status

    Show UFW status

    sudo ufw enable

    Enable UFW

    sudo ufw allow 22/tcp

    Allow TCP port 22

    sudo ufw deny 23/tcp

    Deny TCP port 23

    sudo ufw delete allow 22/tcp

    Delete an allow rule

    sudo firewall-cmd --state

    Check firewalld status

    sudo firewall-cmd --list-all

    Show active firewalld rules

    sudo firewall-cmd --add-service=http --permanent

    Permanently allow HTTP

    sudo firewall-cmd --reload

    Reload firewalld

    sudo nft list ruleset

    Display nftables rules

    docker version

    Show Docker versions

    docker info

    Show Docker engine information

    docker ps

    List running containers

    docker ps -a

    List all containers

    docker images

    List local images

    docker pull nginx

    Download an image

    docker run --name web -p 8080:80 -d nginx

    Run nginx in the background

    docker stop web

    Stop a container

    docker start web

    Start a stopped container

    docker restart web

    Restart a container

    docker rm web

    Remove a stopped container

    docker rmi nginx

    Remove an image

    docker logs web

    Show container logs

    docker logs -f web

    Follow container logs

    docker exec -it web bash

    Open a Bash shell inside a container

    docker inspect web

    Show detailed metadata

    docker stats

    Show live resource usage

    docker volume ls

    List volumes

    docker network ls

    List networks

    docker compose up -d

    Start a Compose project

    docker compose down

    Stop and remove Compose resources

    docker compose logs -f

    Follow Compose logs

    git init

    Initialize a repository

    git clone URL

    Clone a remote repository

    git status

    Show repository status

    git add file

    Stage a file

    git add .

    Stage changes under the current directory

    git commit -m 'message'

    Create a commit

    git log --oneline --graph --decorate

    Show a compact commit graph

    git diff

    Show unstaged changes

    git diff --staged

    Show staged changes

    git branch

    List branches

    git switch branch

    Switch branches

    git switch -c newbranch

    Create and switch branches

    git merge branch

    Merge a branch

    git pull

    Fetch and integrate remote changes

    git push

    Push commits

    git remote -v

    Show remotes

    lspci -nn

    List PCI devices with numeric IDs

    lsusb -v

    Show verbose USB information

    lsmod

    List loaded kernel modules

    modinfo module

    Show module information

    sudo modprobe module

    Load a kernel module

    sudo modprobe -r module

    Unload a kernel module

    udevadm info /dev/sda

    Query udev device information

    smartctl -a /dev/sda

    Show SMART disk health

    nvme list

    List NVMe devices

    nvme smart-log /dev/nvme0

    Show NVMe health information

    top

    Live process and resource view

    htop

    Enhanced process monitor

    free -h

    Memory and swap usage

    vmstat 1

    Sample memory and CPU every second

    iostat -xz 1

    Detailed disk I/O statistics

    iotop

    Show processes performing disk I/O

    mpstat -P ALL 1

    Show per-CPU usage

    sar -u 1 5

    Collect CPU statistics

    pidstat 1

    Show per-process resource usage

    du -ah .

    sort -h | tail -20|Show the 20 largest items below current directory

    find . -type f

    wc -l|Count files recursively

    find . -type f -empty

    Find empty files

    find . -type d -empty

    Find empty directories

    ps aux --sort=-%mem

    head|Show top memory-consuming processes

    ps aux --sort=-%cpu

    head|Show top CPU-consuming processes

    ss -tulpn

    grep LISTEN|Show listening sockets

    journalctl -p err -b

    Show errors from current boot

    ip -br a

    Quick network summary

    df -hT

    Show disk usage and filesystem types

    grep -Rni 'searchterm' .

    Recursive case-insensitive search with line numbers

    find . -type f -mtime -1

    Find files modified in the last 24 hours

    find . -type f -mtime +30

    Find files older than 30 days

    tar -czf backup-$(date +%F).tar.gz /path/to/data

    Create a dated compressed backup

    man command

    Open a manual page

    command --help

    Show command help

    info command

    Open GNU Info documentation

    apropos keyword

    Search manual-page descriptions

    whatis command

    Show a one-line command description

    tldr command

    Show example-focused documentation if installed

    Linux Command Cheat Sheet • Offline-ready • Search and copy buttons run locally in your browser.
    Previous Post
    Next Post

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Company

    About Us

    Tools

    Features

    Blogs

    Contac Us

    +1-(419) 999-9999

    Lima, OH
    45804

    Follow Us

    Check out our socials!

    © 2026 Learn2Lan – Created By Seth Busch & David Miller