Commands
149 commands, grouped by what you are trying to do. Each page has the most useful forms, run for real, with pitfalls and the GNU vs macOS differences.
Files and directories
Create, copy, move, link and inspect files and directories. Cheat sheet
basenameStrip the directory part (and optionally a suffix) from a path, leaving the file name.cdChange the shell's current working directory.chownChange the owner and/or group of files and directories.cpCopy files and directories, optionally keeping their timestamps, permissions and links.dirnameStrip the last component from a path, leaving the directory part.fileGuess what kind of data a file holds by looking at its contents, not its name.installCopy files into place and set their mode, owner and group in one step; can also create directories.lnMake links between files, symbolic (-s) or hard.lsList the contents of directories, or the details of individual files.mkdirCreate directories, optionally with all missing parents.mktempCreate a temporary file or directory with a unique, unpredictable name and print that name.mvMove or rename files and directories.pwdPrint the full path of the current working directory.readlinkPrint where a symbolic link points, or with -f the fully resolved path of any file.realpathPrint the absolute, canonical path of a file, with symlinks, . and .. resolved.rmDelete files, and with -r whole directory trees. There is no undo.rmdirRemove empty directories, and refuse if they are not empty.statShow a file's metadata (size, permissions, owner, inode, timestamps), or print chosen fields in your own format.touchUpdate a file's timestamps, creating it empty if it does not exist.treeDraw a directory and everything below it as an indented tree.
Viewing files
Look inside files: the start, the end, line counts and raw bytes. Cheat sheet
catConcatenate files and print them to standard output; also the quickest way to see a short file.headPrint the first lines (or bytes) of files; 10 lines by default.hexdumpDisplay file contents in hex, octal, decimal or ASCII, with a canonical hex-plus-text layout via -C.lessPage through a file or command output one screen at a time, with search and scrolling in both directions.nlPrint files with line numbers added, with control over which lines get numbered and how.odDump a file's bytes as octal, hex, decimal or characters, to see exactly what it contains.tacPrint files with their lines in reverse order, last line first.tailPrint the last lines of files, or follow a file as it grows with -f.wcCount lines, words, characters and bytes in files or standard input.xxdMake a hex dump of a file, or turn a hex dump back into binary with -r.
Text processing
Filter, cut, sort, transform and compare text, the shell's real superpower. Cheat sheet
awkScan text as records and fields, and run a small program on each line that matches a pattern.base64Encode binary data as base64 text, or decode base64 back to the original bytes with -d.bcAn arbitrary-precision calculator language, used from scripts for decimal math the shell cannot do.cmpCompare two files byte by byte and report the first difference, or just whether they differ.columnFormat input into aligned columns or a table; turns CSV and whitespace data into readable output.commCompare two sorted files line by line and show lines unique to each and lines in both.cutPrint selected fields, characters or bytes from each line, such as columns of a CSV or TSV file.diffCompare two files or directories line by line and print the changes that turn one into the other.echoPrint its arguments separated by spaces, followed by a newline.envsubstReplace $VAR and ${VAR} references in text with the values of environment variables.expandConvert tabs to spaces, keeping the columns where they were; unexpand does the reverse.exprEvaluate an integer, comparison or string expression given as separate arguments and print the result.fmtReflow text into paragraphs of a given width, joining short lines and wrapping long ones.foldWrap long lines to a fixed width, optionally breaking only at spaces.grepPrint the lines of files (or standard input) that match a pattern.iconvConvert text from one character encoding to another, such as Latin-1 or UTF-16 to UTF-8.joinJoin lines of two sorted files that share a key field, like a database join on text files.jqQuery, filter and reshape JSON from the command line with a small expression language.md5sumCompute or verify MD5 checksums; fine for spotting accidental changes, not for security.pasteMerge lines of files side by side, or join all lines of one file into a single line.patchApply a diff to files, turning the original versions into the changed ones.printfPrint text and values through a format string, with precise control over spacing, numbers and escapes.revReverse the characters of every line.sedEdit a stream of text with a script of commands, most often to substitute text or delete lines.seqPrint a sequence of numbers, with a chosen start, step, separator and format.sha256sumCompute SHA-256 checksums of files, or verify files against a list of checksums with -c.shufShuffle lines into random order, or pick random lines, numbers or words.sortSort lines of text alphabetically, numerically, by version or by chosen fields; also merge and de-duplicate.splitSplit a file into pieces by number of lines, by size or into N equal parts.teeCopy standard input to standard output and to one or more files at the same time.trTranslate, squeeze or delete characters from standard input; for case changes, line endings and stripping characters.uniqCollapse or report repeated adjacent lines; with sort, count how often each line occurs.
Finding things
Find files by name, size or age, and feed them to other commands. Cheat sheet
findWalk a directory tree and print, or act on, every file that matches a set of tests.whereisLocate the binary, source and manual page files for a command in the standard system directories.whichShow which executable file in PATH would run for a command name.xargsRead items from standard input and run a command with them as arguments, in batches or in parallel.
Archives and compression
Pack, compress and unpack tarballs, zips and friends. Cheat sheet
bzip2Compress files to .bz2 with the Burrows-Wheeler algorithm, or decompress them with -d, bunzip2 or bzcat.gzipCompress files to .gz (replacing the original by default), or decompress them with -d or gunzip.tarBundle files and directories into one archive, list it, or extract it; optionally compressed with gzip, bzip2, xz or zstd.unzipList, test or extract the files in a .zip archive.xzCompress files to .xz with LZMA2 for high ratios, or decompress them with -d, unxz or xzcat.zcatPrint the decompressed contents of gzip files to standard output, leaving the files compressed.zipPackage and compress files into a .zip archive, the format every operating system opens natively.zstdCompress files to .zst with Zstandard, fast at any ratio; decompress with -d, unzstd or zstdcat.
Processes and jobs
See what is running, stop it, background it, time it. Cheat sheet
bgResume a stopped job in the background, as if it had been started with &.fgBring a background or stopped job into the foreground, so it gets the terminal and the shell waits for it.jobsList the background and stopped jobs of the current shell, with their job numbers and state.killSend a signal to processes by PID or job number; by default TERM, which asks a process to exit.killallSend a signal (TERM by default) to all processes running a program with the given name.lsofList open files and the processes holding them, including network sockets, deleted files and working directories.niceRun a command with a lower (or, as root, higher) CPU scheduling priority, or print the current niceness.nohupRun a command immune to the hangup signal, so it keeps running after you log out or close the terminal.pgrepPrint the PIDs of processes whose name (or full command line) matches a pattern, with filters by user, parent and age.pkillSend a signal (TERM by default) to every process whose name or command line matches a pattern.psPrint a snapshot of running processes, with the columns, filters and sort order you choose.pstreeDisplay running processes as a tree, showing which process started which.reniceChange the niceness (CPU scheduling priority) of processes that are already running, by PID, process group or user.sleepPause for a given amount of time, in seconds by default, with m, h and d suffixes and fractions allowed.timeMeasure how long a command takes (wall-clock, user and system CPU time); GNU /usr/bin/time also reports memory and I/O.timeoutRun a command with a time limit, and kill it if it is still running when the time is up.topShow a live, sorted view of processes and system load; batch mode prints snapshots for logs and scripts.waitWait for background jobs of the current shell to finish, and return their exit status.watchRerun a command every few seconds and show its output full-screen, optionally highlighting changes or exiting when they happen.
System and users
Who you are, what the machine is doing, dates, services and logs. Cheat sheet
calPrint a calendar for a month, a few months, or a whole year.datePrint the current date and time in any format, or convert and calculate dates.envPrint the environment, or run a command with a modified environment.freeShow how much RAM and swap is in use, free, and available to new programs.groupsPrint the groups the current user, or each named user, belongs to.idPrint the user and group IDs of the current user or of a named user.journalctlRead and filter the systemd journal, the log store for services, the kernel and the boot process.printenvPrint all environment variables, or the values of the ones you name.systemctlStart, stop, enable and inspect services and other units managed by systemd.unamePrint the kernel name, release and version, the hostname, and the machine hardware type.uptimeShow how long the system has been running, how many users are logged in, and the load averages.vmstatReport processes, memory, swap, I/O and CPU activity, once or at a regular interval.whoamiPrint the user name of the effective user ID the current process runs as.
Disks and filesystems
Space used, space free, and what is mounted where. Cheat sheet
ddCopy bytes between files or devices in fixed-size blocks, with optional offsets and conversions.dfReport how much space is used and free on mounted filesystems.duShow how much disk space files and directories use, totalled per directory.findmntShow mounted filesystems as a tree, or look up which filesystem a path is on and how it is mounted.lsblkList block devices (disks, partitions, LVM volumes, loop devices) as a tree, with sizes and mount points.mountAttach a filesystem (a disk partition, image, network share or tmpfs) to a directory, or list what is mounted.truncateShrink or extend a file to an exact size, creating it if needed.
Networking and remote
HTTP requests, remote shells, file sync and sockets. Cheat sheet
curlTransfer data to or from a URL; the standard tool for HTTP requests, API calls and downloads from the shell.hostnamePrint the system's host name, its short or fully qualified form, or its IP addresses.ipShow and change network interfaces, addresses, routes and neighbors on Linux (iproute2).ncOpen raw TCP or UDP connections, or listen for them; for testing ports, talking to services by hand and piping data between hosts.pingSend ICMP echo requests to a host and report replies and round-trip times, to test reachability and latency.rsyncCopy and synchronize files and directories, locally or over ssh, transferring only what changed.scpCopy files between hosts over ssh, with cp-like syntax where a remote path is written HOST:PATH.ssList network sockets on Linux; above all, which ports are listening and which connections are open.sshLog in to a remote machine or run a command on it over an encrypted connection; also forwards ports and jumps through hosts.ssh-copy-idInstall your public SSH key in a remote account's authorized_keys so you can log in without a password.ssh-keygenCreate, inspect and manage SSH keys, and maintain known_hosts entries.wgetDownload files over HTTP, HTTPS and FTP, non-interactively, with retries, resuming and recursive mirroring.
Shell builtins
Commands built into bash itself: variables, options, tests and control. Cheat sheet
aliasDefine a short name that the shell replaces with a longer command line, or list the aliases already defined.commandRun a command while skipping functions and aliases of the same name, or check whether a command exists with -v.declareCreate variables with attributes (array, associative array, integer, read-only, exported), or show how variables are defined.evalJoin the arguments into a string and run it as shell code, with a second round of parsing and expansion.execReplace the shell with another program, or, with only redirections, change where the shell's own input and output go.exportMark shell variables (or bash functions) to be passed to every program the shell starts.falseDo nothing and exit with status 1 (failure).getoptsParse short command-line options such as -v and -o FILE in a script, one option per call, inside a while loop.localDeclare variables inside a function that disappear when it returns, leaving any global of the same name untouched.mapfileRead lines from standard input into an indexed array, one line per element (also called readarray).popdRemove the top directory from the directory stack and change back to the next one.pushdChange to a directory and remember the previous one on a stack, so popd can return to it.readRead one line from standard input and split it into shell variables.setTurn shell options such as -e, -u, -x and pipefail on or off, and replace the positional parameters.shiftDrop the first N positional parameters ($1, $2, ...) and renumber the rest down.sourceRun the commands in a file inside the current shell, so its variables, functions and directory changes stay in effect.testEvaluate a condition about files, strings or integers and return 0 for true or 1 for false.trapRun a command when the shell receives a signal or exits, typically to clean up temporary files.trueDo nothing and exit with status 0 (success).typeShow how the shell would interpret a name, as an alias, keyword, function, builtin or file on PATH.ulimitShow or set per-process resource limits such as open files, core size and stack size.umaskShow or set the mask that removes permission bits from newly created files and directories.unsetRemove shell variables, array elements or functions, so they no longer exist rather than being empty.yesPrint a line (y by default) over and over until killed or the reader stops reading.