ls
List files and folders in a directory.
Syntax: ls [options] [path]
- -l
- long format: permissions, owner, size, date
- -a
- include hidden dotfiles
- -h
- human-readable sizes with -l
- -t
- sort by modified time, newest first
$ ls -lahFree developer tool
A Linux commands cheat sheet is a quick reference for the terminal commands you use to manage files, text, permissions, processes, disks, networks, packages, users and services. Search 103 common commands by name or task, see the syntax and flags that matter, copy a working example and spot the risky ones before you run them.
Showing 103 of 103 commands
List files and folders in a directory.
Syntax: ls [options] [path]
$ ls -lahChange the current working directory.
Syntax: cd [directory]
$ cd ~/projects/appPrint the full path of the current directory.
Syntax: pwd
$ pwdCreate one or more directories.
Syntax: mkdir [options] directory...
$ mkdir -p src/components/uiCreate an empty file or update a file's timestamp.
Syntax: touch file...
$ touch notes.txtCopy files or directories.
Syntax: cp [options] source... destination
$ cp -r config/ config.bak/Careful: Overwrites files at the destination without asking unless you add -i.
Move or rename files and directories.
Syntax: mv [options] source... destination
$ mv draft.md final.mdCareful: Overwrites a file with the same name at the destination unless you add -i or -n.
Delete files or directories permanently. There is no trash.
Syntax: rm [options] file...
$ rm -ri old-build/Careful: Deleted files do not go to a trash folder. Check the path before using -r or -f, and never run rm -rf with a variable that might be empty.
Remove an empty directory.
Syntax: rmdir directory...
$ rmdir empty-folderCreate links between files. Use -s for a symbolic link.
Syntax: ln -s target link_name
$ ln -s /opt/app/current/bin/app ~/bin/appSearch for files by name, type, size, age and more, then optionally act on them.
Syntax: find [path] [tests] [actions]
$ find . -type f -name "*.log" -mtime +30Show a directory as an indented tree. Often needs installing first.
Syntax: tree [options] [path]
$ tree -L 2 srcShow detailed file information: size, permissions, inode and timestamps.
Syntax: stat file
$ stat package.jsonIdentify a file's type from its contents, not its extension.
Syntax: file file...
$ file download.binPrint a file's contents, or join several files.
Syntax: cat [options] file...
$ cat /etc/os-releasePage through a long file. Press / to search and q to quit.
Syntax: less [options] file
$ less /var/log/syslogShow the first lines of a file.
Syntax: head [-n count] file
$ head -n 20 data.csvShow the last lines of a file, or follow it as it grows.
Syntax: tail [options] file
$ tail -f /var/log/nginx/error.logSearch text for lines that match a pattern.
Syntax: grep [options] pattern [file...]
$ grep -rn "TODO" src/Count lines, words and bytes.
Syntax: wc [options] file...
$ wc -l access.logSort lines of text.
Syntax: sort [options] file
$ sort -n -r -k 2 scores.txtCollapse repeated adjacent lines. Usually used after sort.
Syntax: uniq [options] [file]
$ sort ips.txt | uniq -c | sort -nr | headExtract columns or character ranges from each line.
Syntax: cut -d delimiter -f fields file
$ cut -d: -f1 /etc/passwdProcess text by fields and patterns. Ideal for columns in logs and command output.
Syntax: awk 'pattern { action }' file
$ awk '{ print $1 }' access.log | sort | uniq -cFind and replace or edit text in a stream or file.
Syntax: sed [options] 's/find/replace/g' file
$ sed -i 's/http:/https:/g' links.txtCareful: sed -i rewrites the file. Run it without -i first to preview, or use -i.bak to keep a backup. On macOS, -i needs an argument: sed -i '' ...
Compare two files line by line.
Syntax: diff [options] file1 file2
$ diff -u old.conf new.confWrite output to a file and the screen at the same time.
Syntax: command | tee [-a] file
$ npm run build 2>&1 | tee build.logTurn input lines into arguments for another command.
Syntax: command | xargs [options] command
$ find . -name "*.tmp" -print0 | xargs -0 rmCareful: Pairing xargs with rm deletes every matched file. Run the find part alone first to see the list.
Change who can read, write or execute a file.
Syntax: chmod [options] mode file...
$ chmod +x deploy.shCareful: chmod -R 777 makes files writable by every user. Use the narrowest permission that works.
Change a file's owner and group.
Syntax: chown [options] user[:group] file...
$ sudo chown -R www-data:www-data /var/www/siteChange a file's group.
Syntax: chgrp [options] group file...
$ sudo chgrp -R developers /srv/sharedShow or set default permissions for new files.
Syntax: umask [mask]
$ umask 022Run a command as root or another user.
Syntax: sudo [options] command
$ sudo systemctl restart nginxList running processes.
Syntax: ps [options]
$ ps aux | grep nodeLive view of processes, CPU and memory. Press q to quit.
Syntax: top
$ top -u www-dataFriendlier interactive process viewer. Usually needs installing first.
Syntax: htop
$ htopSend a signal to a process by PID. The default asks it to stop.
Syntax: kill [-signal] pid
$ kill 4821Careful: kill -9 gives the process no chance to save data. Try the default signal first.
Send a signal to processes by name.
Syntax: pkill [options] pattern
$ pkill -f "node server.js"Careful: Every process whose name matches is signalled. Check with pgrep first.
Find process IDs by name.
Syntax: pgrep [options] pattern
$ pgrep -a nginxList background jobs in the current shell.
Syntax: jobs [-l]
$ jobs -lResume a stopped job in the background or bring it to the foreground. Ctrl+Z stops the current job.
Syntax: bg [%job] · fg [%job]
$ fg %1Run a command that keeps going after you log out.
Syntax: nohup command [args] &
$ nohup ./backup.sh > backup.log 2>&1 &Start a command with lower or higher CPU priority.
Syntax: nice -n priority command
$ nice -n 10 tar -czf backup.tar.gz /dataList open files, including which process uses a port.
Syntax: lsof [options]
$ sudo lsof -i :3000Show free and used space on mounted disks.
Syntax: df [options] [path]
$ df -hShow how much space files and folders use.
Syntax: du [options] [path]
$ du -h -d 1 /var | sort -hShow memory and swap usage.
Syntax: free [options]
$ free -hShow kernel and system information.
Syntax: uname [options]
$ uname -rShow how long the system has run and its load averages.
Syntax: uptime
$ uptimeList disks and partitions as a tree.
Syntax: lsblk [options]
$ lsblk -fAttach a filesystem to a folder, or list mounts.
Syntax: mount [device] [directory]
$ sudo mount /dev/sdb1 /mnt/usbShow or format the current date and time.
Syntax: date [+format]
$ date +%F-%H%MShow or set the hostname and OS details on systemd systems.
Syntax: hostnamectl [set-hostname name]
$ hostnamectlCopy raw data block by block, for example to write an image to a USB drive.
Syntax: dd if=input of=output [options]
$ sudo dd if=ubuntu.iso of=/dev/sdX bs=4M status=progress conv=fsyncCareful: A wrong of= target erases that disk immediately. Confirm the device with lsblk first.
Show and change network interfaces, addresses and routes. Replaces ifconfig.
Syntax: ip [object] [command]
$ ip aCheck whether a host is reachable and measure round-trip time.
Syntax: ping [options] host
$ ping -c 4 example.comMake HTTP requests and download files.
Syntax: curl [options] url
$ curl -IL https://example.comDownload files from the web.
Syntax: wget [options] url
$ wget -c https://example.com/file.isoShow open sockets and listening ports. Replaces netstat.
Syntax: ss [options]
$ sudo ss -tulpnLook up DNS records.
Syntax: dig [@server] name [type]
$ dig +short example.com MXShow each network hop to a host. May need installing.
Syntax: traceroute host
$ traceroute -n example.comShow the machine's name or IP addresses.
Syntax: hostname [options]
$ hostname -INetcat: test whether a TCP or UDP port is open, or send raw data.
Syntax: nc [options] host port
$ nc -zv db.internal 5432Simple firewall front end on Ubuntu and Debian.
Syntax: sudo ufw [command]
$ sudo ufw allow 443/tcpCareful: Enabling ufw over SSH without allowing port 22 first locks you out.
Create or extract .tar, .tar.gz and other archives.
Syntax: tar [options] archive [files]
$ tar -czvf site.tar.gz public/Extract a compressed tarball. Modern tar detects gzip, bzip2 and xz automatically.
Syntax: tar -xf archive.tar.gz [-C dir]
$ tar -xzf site.tar.gz -C /tmp/siteCompress or decompress single files to .gz.
Syntax: gzip [options] file
$ gzip -k access.logCreate or extract .zip archives.
Syntax: zip -r archive.zip folder · unzip archive.zip
$ unzip release.zip -d release/High-ratio compression to .xz.
Syntax: xz [options] file
$ xz -T0 -k dump.sqlInstall and update software on Debian, Ubuntu and Mint.
Syntax: sudo apt [command] [package]
$ sudo apt update && sudo apt install -y htopInstall and update software on Fedora, RHEL, Rocky and AlmaLinux.
Syntax: sudo dnf [command] [package]
$ sudo dnf install -y htopInstall and update software on Arch and Manjaro.
Syntax: sudo pacman [operation] [package]
$ sudo pacman -S htopInstall and update software on openSUSE.
Syntax: sudo zypper [command] [package]
$ sudo zypper install htopInstall sandboxed Snap packages, common on Ubuntu.
Syntax: sudo snap install package
$ sudo snap install code --classicInstall sandboxed desktop apps from Flathub.
Syntax: flatpak install remote app-id
$ flatpak install flathub org.gimp.GIMPLow-level Debian package tool, for .deb files and package queries.
Syntax: dpkg [options] package
$ sudo dpkg -i ./app_1.2.0_amd64.debPrint the current user name.
Syntax: whoami
$ whoamiShow a user's UID, GID and groups.
Syntax: id [user]
$ id deployCreate a user account. On Debian, adduser is the friendlier wrapper.
Syntax: sudo useradd [options] user
$ sudo useradd -m -s /bin/bash deployChange a user account, for example add it to a group.
Syntax: sudo usermod [options] user
$ sudo usermod -aG docker deployCareful: Using -G without -a replaces all of the user's extra groups, which can remove sudo access.
Change a password.
Syntax: passwd [user]
$ sudo passwd deployList the groups a user belongs to.
Syntax: groups [user]
$ groups deploySwitch to another user in the current terminal.
Syntax: su [-] [user]
$ su - deployOpen a secure shell on a remote machine.
Syntax: ssh [options] user@host
$ ssh -i ~/.ssh/id_ed25519 deploy@203.0.113.10Create an SSH key pair.
Syntax: ssh-keygen [options]
$ ssh-keygen -t ed25519 -C "you@example.com"Install your public key on a server for password-less login.
Syntax: ssh-copy-id [-i key.pub] user@host
$ ssh-copy-id deploy@203.0.113.10Copy files to or from a remote machine over SSH.
Syntax: scp [options] source destination
$ scp -r dist/ deploy@203.0.113.10:/var/www/siteSync files efficiently, locally or over SSH. Only changed parts are sent.
Syntax: rsync [options] source destination
$ rsync -avz --dry-run dist/ deploy@203.0.113.10:/var/www/site/Careful: --delete removes files at the destination. A trailing slash on the source changes what gets copied. Run with -n first.
Start, stop, restart and inspect systemd services.
Syntax: sudo systemctl [command] service
$ sudo systemctl status nginxRead systemd logs.
Syntax: journalctl [options]
$ journalctl -u nginx -fShow kernel messages, such as hardware and driver errors.
Syntax: dmesg [options]
$ sudo dmesg -T | tail -50Schedule recurring commands for a user.
Syntax: crontab [-e | -l]
$ crontab -eCareful: crontab -r deletes every scheduled job with no confirmation, and r sits next to e on the keyboard.
Power off or reboot the machine, now or later.
Syntax: sudo shutdown [option] [time]
$ sudo shutdown -r +5Careful: Ends every session on the machine, including other SSH users.
List previous commands. Ctrl+R searches them as you type.
Syntax: history [n]
$ history | grep dockerCreate a shortcut for a longer command.
Syntax: alias name='command'
$ alias ll='ls -lah'Print text or variables.
Syntax: echo [text]
$ echo "$PATH"Set an environment variable for this shell and its child processes.
Syntax: export NAME=value
$ export NODE_ENV=productionShow the full path of the program a command runs.
Syntax: which command
$ which python3Open the manual page for a command.
Syntax: man command
$ man rsyncRerun a command every few seconds and show the output full screen.
Syntax: watch [-n seconds] command
$ watch -n 5 df -hClear the terminal screen. Ctrl+L does the same.
Syntax: clear
$ clearRun a script in the current shell, for example to reload your config.
Syntax: source file
$ source ~/.bashrcRedirect and pipe: send output to a file, append to it, pass it to another command, or merge errors into output.
Syntax: command > file · command >> file · a | b
$ npm test > test.log 2>&1Careful: A single > empties the file before writing. Use >> to append.
Type a command name such as tar, or a task such as port, disk space or permission.
Pick a category such as Networking or Package managers to narrow the list.
Check the syntax line, the common flags and any Careful note before you run it.
Copy the example, change the file names or hosts to yours and run it in your terminal.
The basic Linux commands are ls (list files), cd (change directory), pwd (show where you are), mkdir (make a folder), cp (copy), mv (move or rename), rm (delete), cat and less (read files), grep (search text), sudo (run as admin) and man (read the manual). Learn these first and most other tasks build on them.
Run sudo ss -tulpn to list every listening port with its process, or sudo lsof -i :3000 for one port. Stop the process with kill followed by its PID.
Run df -h to see free space on each disk, and du -h -d 1 /path | sort -h to see which folders use the most space.
Run tar -xzf file.tar.gz to extract it into the current folder, or add -C /target/folder to extract somewhere else. Use tar -tzf file.tar.gz to list the contents first.
rm -rf, dd, chmod -R 777, crontab -r, usermod -G without -a, rsync --delete and a single > redirect can all destroy data or access with no undo. This cheat sheet marks each one with a Careful note.
Yes. Core commands are the same on every distribution. Only package managers differ: apt on Debian and Ubuntu, dnf on Fedora and RHEL, pacman on Arch and zypper on openSUSE. Most also work in macOS Terminal and WSL on Windows, though some flags differ on macOS.
If you run the same build, deploy or cleanup commands every week, Tornic turns them into deterministic multi-step workflows that run on the Claude Code, Codex or Cursor CLI you already pay for.
Explore Tornic