Skip to main content
Hybrid Toolkit

Tool

Linux Cheatsheet

Look up chmod, find, tar, pipes, and other everyday Linux syntax in seconds.

Search a command or a task, then copy an example into the terminal. Press / to focus search.

66 shown

Shell

  • |

    command1 | command2

    Send one command’s output into the next.

    • ps aux | grep nginx

      Filter a process list

    • cat access.log | grep 404 | wc -l

      Count matching lines

    • ls -lt | head

      Newest files first

  • >

    command > file command >> file

    Write output to a file. > replaces, >> appends.

    • echo hello > out.txt

      Overwrite the file

    • echo more >> out.txt

      Append to the file

    • ls > files.txt

      Save a listing

  • 2>

    command 2> file command > file 2>&1

    Capture error output, or merge it with normal output.

    • make 2> errors.txt

      Errors only

    • cmd > all.log 2>&1

      Stdout and stderr together

    • cmd &> all.log

      Same, shorter form

  • && ||

    cmd1 && cmd2 cmd1 || cmd2

    Run the next command only if the previous one succeeded or failed.

    • mkdir -p dist && cp app dist/

      Run copy only if mkdir worked

    • grep -q ready status.txt || echo missing

      Print a message if grep found nothing

    • test -f .env && echo found

      Check that a file exists

  • $VAR

    export NAME=value echo $NAME

    Read and set environment variables.

    • export PATH="$PATH:/opt/bin"

      Add a directory to PATH

    • echo $HOME

      Print home directory

    • printenv PATH

      Print PATH

  • quotes

    'literal' "expand $VAR"

    Single quotes keep text literal. Double quotes still expand $VAR.

    • echo 'keep $HOME as text'

      No variable expansion

    • echo "user is $USER"

      Expand $USER

    • grep "error 500" app.log

      Pattern with a space

  • *

    * ? [abc] **

    Match many filenames without typing each one.

    • ls *.log

      All .log files

    • rm file-?.txt

      One-character wildcard

    • cp src/*.{js,ts} dist/

      js or ts files

  • tee

    command | tee file

    Print output and save it to a file at the same time.

    • make | tee build.log

      See output and save it

    • echo ok | tee -a notes.txt

      Append to a file

  • history

    history !! !n Ctrl+R

    Re-run a previous command.

    • history 20

      Last 20 commands

    • !!

      Run the previous command

    • !123

      Run history item 123

  • alias

    alias name='command'

    Short name for a command you type often.

    • alias ll='ls -lah'

      ll → ls -lah

    • alias

      List aliases

    • unalias ll

      Remove an alias

  • echo

    echo [text]

    Print text. Useful in scripts and redirects.

    • echo hello

      Print text

    • echo -n no-newline

      No newline

    • printf "%s\n" "$HOME"

      printf form

Files

  • ls

    ls [options] [path]

    List files in a directory.

    • ls

      Names only

    • ls -lah

      Long list, hidden, human sizes

    • ls -lt

      Newest first

  • cd

    cd [path]

    Change the current directory.

    • cd

      Go home

    • cd /var/log

      Go to a path

    • cd ..

      Up one level

    • cd -

      Previous directory

  • pwd

    pwd

    Show the current directory path.

    • pwd

      Where am I

  • mkdir

    mkdir [-p] dir

    Create a directory. -p also creates parents.

    • mkdir logs

      One folder

    • mkdir -p src/app/utils

      Nested folders

  • rm

    rm [-r] [-f] path

    Delete files or directories. Cannot undo.

    • rm file.txt

      Delete a file

    • rm -r old-dir/

      Delete a directory

    • rm -rf tmp/

      Force, no promptDestructive

  • cp

    cp [-r] src dest

    Copy files or directories.

    • cp a.txt b.txt

      Copy a file

    • cp -r src/ backup/

      Copy a directory

    • cp -p file.txt backup.txt

      Keep timestamps

  • mv

    mv src dest

    Move or rename a file.

    • mv old.txt new.txt

      Rename

    • mv file.txt /tmp/

      Move to another folder

  • find

    find <path> [expression]

    Find files by name, time, type, or size.

    • find . -name "*.log"

      By filename

    • find /var -mtime -7

      Modified in the last 7 days

    • find . -type f -size +100M

      Files larger than 100MB

    • find . -name "*.tmp" -delete

      Delete matchesDestructive

  • touch

    touch file

    Create an empty file, or update its timestamp.

    • touch notes.txt

      Create one file

    • touch a.txt b.txt

      Create several

  • ln

    ln -s target link

    Create a shortcut (symbolic link) to another path.

    • ln -s /opt/app/bin/tool ./tool

      Make a symlink

    • ls -l tool

      Confirm the link

View

  • cat

    cat file

    Print a whole file.

    • cat README.md

      Print a file

    • cat a.txt b.txt

      Concatenate two files

    • cat > notes.txt

      Type into a new file (Ctrl+D to end)

  • less

    less file

    Page through a file. q to quit, / to search.

    • less /var/log/syslog

      Open a log

    • dmesg | less

      Page command output

  • head

    head [-n N] file

    Show the first lines of a file.

    • head file.txt

      First 10 lines

    • head -n 20 file.txt

      First 20 lines

  • tail

    tail [-n N] [-f] file

    Show the last lines. -f follows a log as it grows.

    • tail file.txt

      Last 10 lines

    • tail -n 50 file.txt

      Last 50 lines

    • tail -f /var/log/nginx/access.log

      Follow a live log

  • wc

    wc [-l] [-w] [-c] file

    Count lines, words, or characters.

    • wc -l file.txt

      Line count

    • wc file.txt

      Lines, words, bytes

  • diff

    diff file1 file2

    Show the difference between two files.

    • diff a.txt b.txt

      Basic diff

    • diff -u old.txt new.txt

      Unified diff

  • date

    date [+format]

    Print the current date, time, or Unix timestamp.

    • date

      Local date and time

    • date +%Y-%m-%d

      YYYY-MM-DD

    • date +%s

      Unix seconds

Text

  • grep

    grep [options] pattern [file]

    Find lines that match a pattern.

    • grep error app.log

      Match in one file

    • grep -i error app.log

      Ignore case

    • grep -n -r "TODO" src/

      Recursive, with line numbers

    • grep -v debug app.log

      Invert: lines that do not match

  • sed

    sed 's/old/new/g' file

    Replace text in a file or stream.

    • sed 's/foo/bar/g' file.txt

      Print replaced text

    • sed -i 's/foo/bar/g' file.txt

      Edit the file in place

    • sed '/^#/d' file.txt

      Drop comment lines

  • awk

    awk '{print $N}' file

    Print selected columns, or simple totals.

    • awk '{print $1}' file.txt

      First column

    • awk -F, '{print $1,$3}' data.csv

      CSV columns 1 and 3

    • awk '{sum+=$1} END {print sum}' nums.txt

      Sum a column

  • cut

    cut -d SEP -f N file

    Take a column from delimited text.

    • cut -d',' -f1 data.csv

      CSV first column

    • cut -d: -f1 /etc/passwd

      Username from passwd

    • cut -c1-10 file.txt

      First 10 characters

  • sort

    sort [options] file

    Sort lines. -n sorts numbers.

    • sort file.txt

      Alphabetical

    • sort -n nums.txt

      Numeric

    • sort -r file.txt

      Reverse

  • uniq

    sort file | uniq

    Drop duplicate lines. Sort first.

    • sort file.txt | uniq

      Unique lines

    • sort file.txt | uniq -c

      Count each line

    • sort file.txt | uniq -d

      Only duplicates

  • xargs

    command | xargs [command]

    Turn a list of names into arguments for another command.

    • find . -name "*.log" | xargs grep error

      Grep in found files

    • cat urls.txt | xargs curl -O

      Download each URL

    • find . -name "*.tmp" | xargs rm

      Delete found files

Process

  • ps

    ps [options]

    List running processes and PIDs.

    • ps aux

      All processes

    • ps aux | grep node

      Find by name

    • ps -ef --forest

      Process tree

  • top

    top htop

    Live CPU and memory view. q to quit.

    • top

      Interactive monitor

    • top -p 1234

      One PID

    • htop

      If htop is installed

  • kill

    kill [-SIGNAL] PID

    Stop a process by PID. Try without -9 first.

    • kill 1234

      SIGTERM, polite stop

    • kill -15 1234

      Same as default SIGTERM

    • kill -9 1234

      Force killDestructive

  • pkill

    pkill name killall name

    Stop processes by name instead of PID.

    • pkill nginx

      By name

    • killall node

      killall form

    • pgrep -a node

      Show matching processes

  • jobs

    jobs bg fg command &

    Run a command in the background, or bring it back.

    • sleep 60 &

      Start in background

    • jobs

      List jobs

    • fg %1

      Bring to foreground

    • bg %1

      Resume in background

  • nohup

    nohup command &

    Keep a command running after you disconnect.

    • nohup ./server &

      Survive logout

    • nohup npm start > app.log 2>&1 &

      Save output to a log

  • free

    free -h

    Show RAM and swap. uptime shows load.

    • free -h

      Human-readable memory

    • uptime

      Uptime and load

  • uname

    uname [-a] [-r] [-m]

    Show kernel and architecture.

    • uname -a

      All kernel info

    • uname -r

      Kernel version

    • lscpu

      CPU details

  • watch

    watch [-n N] command

    Re-run a command every few seconds.

    • watch -n 1 df -h

      Refresh every second

    • watch -n 2 'ps aux | grep nginx'

      Watch a filtered process list

Network

  • ip

    ip addr ip route

    Show addresses and routes. Replaces ifconfig.

    • ip addr

      Addresses

    • ip route

      Routes

    • ip link

      Interfaces

  • ping

    ping [-c N] host

    Check whether a host is reachable.

    • ping 8.8.8.8

      Until Ctrl+C

    • ping -c 4 example.com

      Four packets then stop

  • ss

    ss -tuln

    See listening ports. Replaces netstat.

    • ss -tuln

      Listening TCP/UDP ports

    • ss -tulnp

      Include process names

    • ss -tuln | grep :80

      Filter port 80

  • curl

    curl [options] URL

    Call an HTTP URL. Good for APIs and downloads.

    • curl https://example.com

      GET body

    • curl -I https://example.com

      Headers only

    • curl -X POST -H 'Content-Type: application/json' -d '{"ok":true}' https://api.example.com

      JSON POST

    • curl -o file.tgz https://example.com/file.tgz

      Save to a file

  • wget

    wget URL

    Download a file.

    • wget https://example.com/file.tgz

      Download

    • wget -c https://example.com/file.tgz

      Resume a partial download

  • scp

    scp src user@host:dest

    Copy a file over SSH.

    • scp file.txt user@host:/tmp/

      Local → remote

    • scp user@host:/var/log/app.log .

      Remote → local

    • scp -r dist/ user@host:/var/www/

      Copy a directory

  • rsync

    rsync -avz src dest

    Sync directories. Copies only what changed.

    • rsync -avz ./src/ user@host:/opt/app/

      Sync to a server

    • rsync -avz --progress src/ dest/

      Show progress

    • rsync -avz --delete src/ dest/

      Delete extra files on dest

  • ssh

    ssh user@host

    Log in to a remote machine.

    • ssh user@192.168.1.10

      Password or key login

    • ssh -i ~/.ssh/id_ed25519 user@host

      Choose a key file

    • ssh user@host -p 2222

      Custom port

  • lsof

    lsof -i :port

    See which process is using a port.

    • lsof -i :3000

      Who uses port 3000

    • lsof -i TCP:80

      TCP port 80

    • lsof -p 1234

      Files a PID has open

Archive

  • tar

    tar -c|x -z -f archive.tar.gz [path]

    Pack or unpack .tar.gz. z=gzip, c=create, x=extract, f=file.

    • tar -czf backup.tar.gz src/

      Create .tar.gz

    • tar -xzf backup.tar.gz

      Extract here

    • tar -tzf backup.tar.gz

      List contents

    • tar -xzf backup.tar.gz -C /tmp/

      Extract to a folder

  • gzip

    gzip file gunzip file.gz

    Compress or decompress a single file.

    • gzip file.txt

      Creates file.txt.gz

    • gunzip file.txt.gz

      Restore the file

    • gzip -k file.txt

      Keep the original

  • zip

    zip archive.zip files unzip archive.zip

    Create or extract a .zip archive.

    • zip backup.zip a.txt b.txt

      Zip files

    • zip -r backup.zip src/

      Zip a directory

    • unzip backup.zip

      Extract here

    • unzip -l backup.zip

      List contents

  • df

    df -h

    Disk space by filesystem.

    • df -h

      All filesystems

    • df -h .

      This directory’s disk

  • du

    du -h [path]

    Which folders are using space.

    • du -sh .

      Total for this folder

    • du -h --max-depth=1

      One level of subfolders

    • du -h | sort -hr | head

      Largest first

Permissions

  • chmod

    chmod MODE file

    Change permission bits. 755 = rwxr-xr-x, 644 = rw-r--r--.

    • chmod 755 script.sh

      Owner rwx, others rx (scripts/dirs)

    • chmod +x script.sh

      Make executable

    • chmod 644 file.txt

      Owner rw, others r (normal files)

    • chmod -R 755 dir/

      Recursive

    • chmod 777 file

      World-writable, avoidDestructive

  • chown

    chown user:group file

    Change file owner and group.

    • chown www-data:www-data app.sock

      One file

    • chown -R deploy:deploy /var/www/

      Recursive

  • sudo

    sudo command su - user

    Run one command as root, or switch user.

    • sudo apt update

      One command as root

    • sudo -u www-data command

      Run as another user

    • su -

      Root shell

    • sudo visudo

      Edit sudoers safely

  • whoami

    whoami id groups

    Show the current user and groups.

    • whoami

      Username

    • id

      UID and groups

    • groups

      Group names

    • who

      Logged-in users

Packages

  • apt

    apt update apt install pkg

    Install packages on Debian and Ubuntu.

    • sudo apt update

      Refresh package list

    • sudo apt install curl

      Install

    • apt search nginx

      Search

    • sudo apt remove curl

      Remove

    • apt show curl

      Package info

  • dnf

    dnf install pkg yum install pkg

    Install packages on Fedora, RHEL, and CentOS.

    • sudo dnf install curl

      Install (Fedora/RHEL)

    • sudo dnf update

      Update

    • dnf search nginx

      Search

    • sudo yum install curl

      Older yum form

Services

  • systemctl

    systemctl start|stop|status|enable name

    Start, stop, or enable a service.

    • systemctl status nginx

      Is it running?

    • sudo systemctl start nginx

      Start now

    • sudo systemctl restart nginx

      Restart

    • sudo systemctl enable nginx

      Start on boot

    • systemctl --failed

      Failed units

  • journalctl

    journalctl -u name [-f]

    Read service logs.

    • journalctl -u nginx

      This service

    • journalctl -u nginx -f

      Follow live

    • journalctl -p err -n 50

      Recent errors

    • dmesg | tail

      Kernel messages

How to use

Type a command name or what you want to do (unzip, permissions, kill a process). Filter by category if you like. Copy an example and paste it into your terminal. Press / to jump to search.

FAQ

Is this a full manual?
No. Each command keeps a syntax line and a few copy-ready examples. Use man or --help when you need every flag.
Can I search in Chinese or English?
Yes. Try find, chmod, 解压, 管道, or kill process. Any token in the name, example, or hint will match.
Does it run commands on a server?
No. This page only helps you look up syntax. Nothing is executed or uploaded.

Related tools