Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        The Work Gym / Free resources

        Linux commands cheat sheet

        The 40 Linux commands you will use most, grouped by job, each with an example you can copy. Each row links to a lesson where you run it in a practice terminal and your result is checked.

        The examples use the GNU tools found on Ubuntu, Debian and most Linux systems. File names like notes.txt and logs/app.log stand for your own files.

        Each row links to a lesson of the Linux and the shell course, where you practice it and your answer is checked. The first unit is free.

        Files and directories

        NameWhat it doesExamplePractice
        pwdPrints the directory you are in.
        pwd
        Paths and the working directory
        ls -laLists files with permissions, owner, size and date, hidden files included.
        ls -la
        Long listings and hidden files
        cdChanges directory. cd .. goes up one level and cd ~ goes to your home directory.
        cd logs
        Paths and the working directory
        mkdir -pCreates a directory; -p also creates any missing parent directories.
        mkdir -p reports/2026/march
        Nested directory trees
        cp -rCopies files; -r copies a directory and everything in it.
        cp -r logs logs-backup
        Recursive copies and backups
        mvMoves a file or renames it.
        mv sales.csv sales-2026.csv
        File moves and precise renames
        rm -rDeletes files; -r deletes a directory and its contents. There is no recycle bin.
        rm -r old-reports
        Safe recursive removal
        findSearches a directory tree for files by name, type, size or age.
        find . -name "*.log"
        File tests and execution actions

        Read files

        NameWhat it doesExamplePractice
        catPrints a whole file.
        cat notes.txt
        Files, pagers and line windows
        lessOpens a long file one screen at a time. Type /word to search and q to quit.
        less logs/app.log
        Files, pagers and line windows
        head, tailThe first lines of a file; tail -n gives the last ones.
        head -n 5 logs/app.log
        Files, pagers and line windows
        tail -fShows the end of a file and keeps printing new lines as they are written. Ctrl+C stops it.
        tail -f logs/app.log
        Log tails and recovery evidence
        wc -lCounts lines (-l), words (-w) or bytes (-c).
        wc -l sales.csv
        Pipelines, exclusions and counts

        Search and edit text

        NameWhat it doesExamplePractice
        grepPrints the lines that match a pattern; -i ignores case and -v shows the lines that do not match.
        grep -i "error" logs/app.log
        Extended regular expressions
        grep -rnSearches every file under a directory and shows the file name and line number of each match.
        grep -rn "TODO" .
        Recursive searches with source lines
        sedFinds and replaces text as it streams through. The file is not changed unless you add -i.
        sed 's/West/Western/g' sales.csv
        Text replacement without source edits
        awkWorks field by field: filter rows, print columns or add them up. -F sets the separator.
        awk -F, 'NR > 1 && $2 > 5 {print $1}' sales.csv
        Field filters and conditional sums
        cutTakes fields out of each line; -d sets the separator and -f picks the fields.
        cut -d, -f2 sales.csv
        Field extraction and case conversion
        trSwaps or deletes characters, such as lower case to upper case.
        tr 'a-z' 'A-Z' < notes.txt
        Field extraction and case conversion
        sort | uniq -csort orders lines, then uniq -c counts each run of equal lines.
        cut -d, -f1 sales.csv | sort | uniq -c
        Sorting and duplicate groups

        Pipes and redirection

        NameWhat it doesExamplePractice
        | (pipe)Sends one command's output into the next command.
        grep -i "error" logs/app.log | wc -l
        Pipelines, exclusions and counts
        > and >>> writes output to a file and replaces what was there; >> adds it to the end.
        echo "checked" >> notes.txt
        Input, overwrite and append
        xargsTurns lines of input into arguments for another command.
        find . -name "*.log" | xargs wc -l
        Streams as command arguments
        && and ||&& runs the next command only if the first one succeeded; || runs it only if the first one failed.
        mkdir -p backup && cp notes.txt backup/
        Exit codes and conditional lists

        Permissions

        NameWhat it doesExamplePractice
        chmodSets permissions. 755 lets the owner read, write and run the file, and everyone else read and run it.
        chmod 755 deploy.sh
        Octal and symbolic modes
        chownChanges a file's owner and group. It usually needs sudo.
        sudo chown www-data:www-data site/
        Owners and administrative changes
        sudoRuns one command as the administrator (root) after asking for your password.
        sudo ls /root
        Owners and administrative changes

        Variables and scripts

        NameWhat it doesExamplePractice
        exportSets a variable that programs started from this shell can read.
        export APP_ENV=production
        Variables and exported settings
        whichShows which file runs when you type a command, found through the directories in $PATH.
        which python3
        Executable discovery through PATH
        $1 (arguments)Runs a script with an argument; inside the script, $1 is the first argument and $# counts them.
        ./deploy.sh staging
        Scripts and positional arguments
        if [ -f ]Runs commands only when a test passes, such as a file existing (-f) or a directory existing (-d).
        if [ -f notes.txt ]; then echo "found"; fi
        File tests and if branches
        forRepeats commands for each item in a list, here each CSV file.
        for f in *.csv; do echo "$f"; done
        For loops and while boundaries

        Processes

        NameWhat it doesExamplePractice
        ps auxLists running processes with their process ID (PID), owner, CPU and memory.
        ps aux
        Process snapshots and signals
        killAsks a process to stop, by its PID. kill -9 forces it when it does not respond.
        kill 4821
        Process snapshots and signals
        topA live view of the processes using the most CPU and memory. q quits.
        top
        Process snapshots and signals
        & and jobs& starts a command in the background; jobs lists what is running there.
        sleep 1 & jobs
        Background jobs and process IDs

        Network and archives

        NameWhat it doesExamplePractice
        curl -IRequests a URL; -I shows only the response headers, such as the status code.
        curl -I https://example.com
        HTTP checks and shell failures
        sshOpens a shell on another machine over an encrypted connection.
        ssh [email protected]
        Remote shell context
        tar -czfPacks a directory into a compressed .tar.gz file.
        tar -czf logs.tar.gz logs/
        Compressed archives and restoration
        tar -xzfUnpacks a .tar.gz file into the current directory.
        tar -xzf backup.tar.gz
        Compressed archives and restoration

        Checked against

        Every row was last checked on Nov 20, 2026.

        Questions

        Do these commands work on Ubuntu, Debian and macOS?

        Yes for Ubuntu, Debian, Fedora and other Linux systems, which use the GNU versions of these commands. macOS uses BSD versions: the common options here work, but a few, such as sed -i, behave differently.

        Can I practice the commands without installing Linux?

        Yes. The Linux playground and the Linux course run a terminal in your browser with sample files, so you can try every command here safely.

        Can I print this Linux cheat sheet?

        Yes. Press Print or save as PDF; the printed layout keeps the commands and examples and leaves out the rest of the page.

        More cheat sheets

        Free resources

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        New accounts get 12 hours of full access: every course, unit, project and exam. The clock starts when you open your first lesson.

        Plan your practice from a job ad or syllabus

        Have a referral code?

        or

        You can keep practicing without an account.

        Change your plan

        Checking the price

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.