Linux command manual
304 commands explained with syntax, options, copy-ready examples and each one's typical mistakes. It is the cheat sheet that goes with the course.
304 commands
pwdPrints the full path of the folder you are in. It is your reference when you get lost.
lsLists the content of a folder. With no arguments, the current one.
cdChanges folder. It is the command you will use most in your whole terminal life.
treeDraws the tree of folders and files, like a diagram.
touchCreates an empty file or updates its modification date.
mkdirCreates folders. With -p it also creates any missing parents.
cpCopies files. For whole folders it needs -r.
mvMoves files or folders. It also renames.
rmDeletes files. With -r, whole folders. There is no recycle bin.
rmdirDeletes folders, but only if they are empty. It is the safe option.
lnCreates links: a shortcut to another file on the system.
statShows the full technical record of a file: size, permissions, dates and owner.
catShows the whole content of a file. It also joins several on screen.
lessOpens the file page by page: you can move, search and quit whenever you want.
headShows the first lines of a file (10 by default).
tailShows the last lines of a file. The log watcher's command.
wcCounts lines, words and characters. With pipes it is a result counter.
grepSearches a pattern inside files and shows only the matching lines.
findFinds files and folders by name, type or size inside a tree.
whichTells the path of the program that runs when you type a command.
sortSorts the lines of a file or of the input. Alphabetical by default.
uniqRemoves consecutive repeated lines and, with -c, counts them.
cutCuts columns or fields from each line. Ideal for separated listings.
trChanges or deletes characters. Very useful to uppercase or clean text.
sedEdits text as a stream: above all, replaces words inside lines.
awkProcesses text by columns and lets you filter and compute in one line.
echoPrints text on screen. With redirection, it writes to files.
chmodChanges the permissions of a file or folder. The basis of Linux security.
chownChanges the owner of a file. It needs administrator privileges.
chgrpChanges the group a file belongs to.
umaskDefines which permissions are REMOVED from new files you create.
whoamiTells which user you are working as right now.
idShows your user number, your main group and the groups you belong to.
suSwitches user inside the same session. It asks for the other user's password.
useraddCreates a new user account. It requires administrator privileges.
userdelDeletes a user account. With -r it also deletes their home folder.
passwdChanges a user's password. With no arguments, your own.
psShows the processes running on the system.
dfShows the free and used space of mounted disks.
duMeasures how much a folder or file takes. The space detective.
freeShows the available RAM and swap area.
unameShows system information: kernel, architecture and host name.
uptimeTells how long the machine has been on and the system load average.
pingChecks whether a host responds and how long it takes.
tracerouteShows the path a packet travels to its destination, hop by hop.
ipInspects and configures the network: addresses, routes and interfaces.
ifconfigThe classic to see network configuration. Today ip is preferred.
ssLists the connections and ports listening on your machine.
sshOpens a session on another machine, encrypted. The gateway to servers.
scpCopies files between your machine and another over the ssh connection.
curlRequests a URL and shows the response. The command to talk to web services.
wgetDownloads files from the internet with a single command.
aptThe Debian and Ubuntu package manager: installs, searches and updates software.
tarPacks files and folders into a single file, with or without compression.
historyShows the commands you have typed in this session, numbered.
aliasCreates custom shortcuts for long commands.
exportDefines environment variables: named values your programs use.
envShows all current environment variables.
manOpens the official manual of a command: Linux's source of truth.
killSends a signal to a process to ask it to finish, pause it or resume it. It is how you tell a program to stop.
pgrepFinds processes by name and returns their PIDs. It is pkill's sibling without killing anything.
pkillKills processes by name, without looking up the PID first.
sleepPauses execution for a while. Very useful in scripts to wait between steps.
topShows a snapshot of every process sorted by usage, with the load and memory summary on top.
htopA more visual alternative to top, with CPU and memory bars and colours. Many people's favourite.
niceRuns a command with lower priority so it does not hog the CPU. It goes from -20 (highest) to 19 (lowest).
reniceChanges the priority of a process that is already running.
jobsLists the jobs launched in the background from this terminal, with their number and state.
fgBrings a background or stopped job back to the foreground.
bgResumes a stopped job in the background, so it keeps going without occupying the terminal.
nohupRuns a command so it keeps working even if you close the terminal. Output is saved to nohup.out.
watchRepeats a command every few seconds to watch for a change: memory, space, connections...
timeoutRuns a command and stops it if it takes longer than allowed. Ideal for scripts and tests.
systemctlManages the system's services (units): start, stop, check whether they are active and decide whether they start with the machine.
journalctlReads the system log, where the messages from services and the kernel end up.
dmesgShows the kernel messages since boot: detected hardware, disks, network and errors.
serviceThe old (SysV) way of managing services. It still works, but systemctl is used today.
dateShows the current date and time. With +FORMAT you can extract just the part you need for file names or reports.
whoLists the users with a session open right now, with their terminal and where they connected from.
lastShows the history of logins and logouts. Useful to know when the machine was used and to spot unusual access.
crontabManages your scheduled tasks: commands the system runs on its own at certain times or days.
printfPrints formatted text. Unlike echo, it reliably interprets sequences such as \n (newline) or \t (tab).
teeShows the output on screen and saves it to a file at the same time. It is the 'T' of a pipeline: it writes to two places.
xargsTurns one command's output into arguments for another. Used when a command does not accept piped input.
diffCompares two files line by line and shows the differences. It is the basis of patches and version control.
jqProcesses and formats JSON from the terminal: extracts fields, filters and shows API data readably.
whereisLocates the binary, the source code and the manual pages of a command.
pstreeShows processes as a tree: who launched whom. It is the best way to see the process hierarchy.
pidofReturns the PID of a program by name. Handy for scripts that need the exact number.
killallSends a signal to every process sharing a name. Useful to close at once a program opened many times.
lscpuSummarises the processor: architecture, cores, threads, frequency and cache. All without opening the machine.
hostnamectlShows and changes the machine name and machine data (operating system, kernel, architecture).
timedatectlShows and adjusts the time, the time zone and network synchronisation (NTP).
calShows a calendar of the month or the year in the terminal.
wShows who is logged in and what they are doing, plus the system load average.
vmstatReports the state of memory, swap, disk I/O and CPU usage in a single table.
localeShows the locale configuration: language, number format, dates and alphabetical sorting.
lsblkLists disks and their partitions as a tree, with sizes and mount points.
blkidShows the UUID and filesystem type of each device. Key to mounting by UUID.
findmntShows mounted filesystems as a tree, indicating which device is at each mount point.
mountMounts a device into a folder so you can access its contents, or lists what is already mounted.
umountUnmounts a device or a folder that was mounted, leaving it ready to be safely removed.
fdiskViews and edits a disk's partitions. With -l it shows the table without entering interactive mode.
mkfs.ext4Formats a partition with the ext4 filesystem, the Linux standard.
mkfs.vfatFormats a partition as FAT32, the format compatible with Windows, cameras and almost any device.
ddCopies data at a low level, block by block. Used to clone disks, create images and fill files.
mkswapPrepares a partition or file to be used as swap memory.
swaponEnables swap memory and shows which one is in use.
swapoffDisables swap memory, returning its contents to RAM.
fsckChecks and repairs the integrity of a filesystem. It is Linux's 'chkdsk'.
setfaclGrants fine-grained permissions to specific users or groups without changing the owner or the basic mode.
getfaclShows the access control list (ACL) of a file or folder.
chattrChanges special file attributes, such as making it immutable so not even root can delete it.
lsattrLists the special attributes of files (such as immutable).
groupaddCreates a new group in the system.
groupdelDeletes a group from the system.
groupmodModifies an existing group, for example renaming it.
groupsShows which groups a user belongs to. With no arguments, the current user.
usermodModifies a user account: groups, shell, home directory, account lock, and more.
chageViews and changes a password's expiry: when it expires and how often it must be changed.
chshChanges a user's default shell.
getentQueries the system databases (users, groups, hosts). It is the right way to check whether an account or group exists.
newgrpChanges the effective group of the current session without logging out.
ufwUbuntu's simple firewall. Enables protection and decides which ports are allowed or blocked.
iptablesLinux's low-level firewall: chains of rules that filter network traffic.
ssh-keygenGenerates an SSH key pair (public and private) to connect to servers without a password.
ssh-copy-idCopies your public key to the remote server so you can log in over SSH without a password.
ncThe network 'Swiss army knife': checks whether a port is open, transfers data or listens.
lsofLists the files opened by processes. With -i, it shows which processes use the network and which ports listen.
digQueries DNS servers and shows the full answer: IP address, servers and timings.
hostResolves domain names to IP addresses and back, with short output.
nslookupQueries DNS interactively or directly. Classic and also available on Windows.
nmcliControls network connections from the terminal: device status, wifi networks and connection profiles.
arpShows the ARP table: the mapping between local IP addresses and network MAC addresses.
routeShows the routing table: where traffic leaves for each network and what the gateway is.
ethtoolShows and adjusts a network card's parameters: speed, duplex and whether the cable is connected.
tcpdumpCaptures the network traffic passing through an interface, to troubleshoot or study protocols.
nmapScans hosts and ports to discover which services are exposed. A basic auditing tool.
seqGenerates a sequence of numbers. Perfect for loops, tests and generating data.
nlNumbers the lines of a file. It is like cat -n but with fine control of the format.
revReverses the character order of each line. Fun and useful for some text tricks.
tacShows a file with the lines in reverse order: the last first. It is 'cat' backwards.
foldWraps long lines into chunks of a given width. Useful to fit text to a screen or page.
fmtReformats paragraphs: joins the lines and splits them again to fill a uniform width.
columnOrganises text into aligned columns. With -t it turns messy output into a clean table.
pasteJoins lines from several files into one, sticking them side by side separated by a tab.
splitSplits a large file into smaller chunks. Very useful to upload or move files in parts.
commCompares two sorted files and shows in columns which lines are only in the first, only in the second or shared.
joinCombines two files by a common field, like a database query but with text.
cmpCompares two files byte by byte and says exactly at which byte and line they differ.
base64Encodes data into safe text (only letters, numbers, + and /) and decodes it back. Useful to embed binaries in text.
xxdShows a file in hexadecimal and its text equivalent, byte by byte. Essential to inspect binary data.
odDumps a file in octal (or other formats) showing its bytes, useful to inspect raw data.
iconvConverts text between character encodings, for example from UTF-8 to ASCII or Latin-1.
dos2unixConverts a file from Windows line endings (CRLF) to Unix (LF). Fixes the classic ^M error.
unix2dosConverts a file from Unix line endings (LF) to Windows (CRLF).
gzipCompresses a file with the gzip algorithm and adds the .gz extension. It is the de facto standard on Linux.
gunzipDecompresses .gz files and recovers the original.
zcatShows the contents of a .gz file without decompressing it to disk. It is cat + gunzip.
bzip2Compresses files with the bzip2 algorithm (.bz2), which usually packs more than gzip at the cost of speed.
bunzip2Decompresses .bz2 files.
bzcatShows the contents of a .bz2 file without decompressing it to disk.
xzCompresses files with the xz algorithm (.xz), the best compressor of the three classics.
unxzDecompresses .xz files.
xzcatShows the contents of a .xz file without decompressing it to disk.
zipCreates .zip compressed archives, the format most compatible with Windows, macOS and almost any program.
unzipExtracts .zip files and can list their contents without extracting.
fileGuesses a file's real type by looking at its content, not its extension. Very useful when you do not know what it is.
trueDoes nothing and exits successfully (code 0). Its use is in scripts, for infinite loops or default values.
falseDoes nothing and exits with an error (code 1). The complement of true.
typeSays what a name is: a binary, a shell builtin or an alias. It answers 'why does this command behave like this'.
sourceRuns a command file in the current shell, so the variables and functions it defines stay in your session.
setWith no arguments, shows every shell variable. It also changes shell behaviour options.
unsetDeletes a variable or function from the shell.
readonlyMarks a variable as read-only: it cannot be changed or deleted during the session.
letPerforms arithmetic and stores the result in variables, right on the command line.
exprEvaluates simple arithmetic and logical expressions from the command line.
bcArbitrary-precision calculator. Unlike the shell, it handles decimals without losing precision.
mktempCreates a temporary file or folder with a unique, safe name, so it does not clash with others.
ulimitShows or limits the resources your session can consume: open files, processes, memory, etc.
dpkgManages .deb packages directly: install them, list them or check which package a file belongs to.
apt-cacheQueries the package catalogue without installing anything: search, view details or check the available version.
snapManages snap packages: applications bundled with all their dependencies that update themselves.
shutdownShuts down or restarts the machine in an orderly way, warning users and closing programs.
rebootRestarts the machine immediately.
poweroffPowers off the machine immediately, in an orderly way.
haltStops the system without necessarily cutting the power. Classic way to halt the machine.
atSchedules a command to run once at a specific time.
atqLists the pending tasks scheduled with at.
atrmDeletes a task scheduled with at, by its number.
straceRuns a program showing the system calls it makes. It is the magnifying glass to understand what it really touches.
fuserSays which processes are using a file, a folder or a port. Very useful before unmounting a USB stick.
readReads a line from the input and stores it in a variable. It is how you ask the user for data in a script.
md5sumComputes the MD5 hash (128 bits) of one or more files. Used to check that a file has not changed.
sha1sumComputes the SHA-1 hash (160 bits) of a file. Stronger than MD5, though SHA-256 is preferred today.
sha256sumComputes the SHA-256 hash (256 bits) of a file. The standard to verify downloads and integrity.
sha512sumComputes the SHA-512 hash (512 bits) of a file. The longest of the SHA-2 family.
egrepLike grep but treating the pattern as an extended regular expression. Equivalent to grep -E.
fgrepLike grep but searching the text literally, without special characters. Equivalent to grep -F.
basenameFrom a full path, shows only the final name of the file or folder.
dirnameFrom a full path, shows the folder that contains it (removes the last segment).
readlinkShows where a symbolic link points. With -f it gives the resolved absolute path.
realpathGives the absolute, real path of a file, resolving links and dots.
truncateChanges a file size: shrinks it or pads it up to the size you ask.
shredOverwrites a file content before deleting it, so it cannot be recovered.
mkfifoCreates a named pipe (FIFO): a special file through which two programs exchange data.
shufRandomly shuffles lines, values or a range of numbers. Handy for draws and tests.
numfmtConverts numbers to human-readable form (1M, 2G) or back. Very useful when reading sizes.
stringsExtracts the readable text inside a file, even if it is binary.
yesRepeats a word endlessly (the letter y by default). Used to answer questions automatically.
lsmodLists the kernel modules currently loaded, with their size and who uses them.
modprobeLoads a kernel module (or unloads it with -r), resolving dependencies.
insmodInserts a specific module from its .ko file, without resolving dependencies.
rmmodUnloads a kernel module. With -f it forces even if in use.
modinfoShows information about a module: file, description, license and dependencies.
sysctlReads or changes kernel parameters live. With -w it applies them and saves to /etc/sysctl.conf.
loginctlShows and manages user sessions and who is logged in (systemd-logind).
resolvectlShows and tests name resolution from systemd-resolved. With query it resolves a name.
localectlShows or changes the system language and keyboard layout.
systemd-analyzeMeasures how long boot takes and which services slow it down. With blame it sorts by time.
loggerWrites a message to the system log (journal), with an optional tag.
nftManages the nftables firewall: creates modern rules (replaces iptables).
firewall-cmdControls firewalld (the Red Hat/Fedora firewall): ports, services and zones.
getenforceShows the current SELinux mode: Enforcing, Permissive or Disabled.
setenforceSwitches SELinux between Enforcing (1) and Permissive (0) live.
semanageManages SELinux settings: ports and file contexts.
restoreconRestores files to their correct SELinux context according to the rules.
chconChanges the SELinux context of a specific file (temporary).
opensslCryptography Swiss army knife: hashes, random numbers, certificates and passwords.
gpgEncrypts and decrypts files or messages with GPG. With -c it uses symmetric encryption.
apt-fileSearches which package a file belongs to, even if it is not installed.
add-apt-repositoryAdds a repository (PPA) to the APT sources so you can install from it.
dpkg-reconfigureReconfigures an already installed package (language, timezone, etc.).
pushdSaves the current folder on a stack and moves to another. Perfect to go and come back.
popdRemoves the last folder from the stack and moves to it.
dirsShows the directory stack you have been saving with pushd.
timeRuns a command and tells you how long it took (real, user and system).
evalRe-interprets the text you pass it as if you had typed it.
declareDeclares or shows variables (and arrays) with their attributes.
localDeclares a local variable inside a function: it does not leak out.
shiftShifts a script arguments left: $1 becomes the old $2.
getoptsWalks through a script options (-a, -b value) one at a time.
trapSchedules an action for when the script exits or receives a signal.
pvcreatePrepares a disk or partition as a physical volume (PV) to use with LVM.
pvsSummarizes the physical volumes (PV), their group and size.
pvdisplayShows the details of each physical volume: size, extent and group.
pvremoveRemoves the LVM label from a physical volume to reuse the disk.
vgcreateCreates a volume group (VG) grouping one or more PVs.
vgextendExtends a volume group by adding more physical disks.
vgsSummary of volume groups: PVs, LVs and size.
vgdisplayDetails of each volume group: size, PE and layout.
lvcreateCreates a logical volume (LV) inside a group, like a flexible partition.
lvextendExtends a logical volume without unmounting it or losing data.
lvreduceShrinks a logical volume. Careful: it can cut data if the filesystem is not adjusted.
lvremoveRemoves a logical volume and frees its space in the group.
lvsSummary of logical volumes: group, attributes and size.
lvdisplayDetails of each logical volume: path, name, group and size.
mdadmCreates and manages software RAID: mirror (raid1), parity (raid5), etc.
partedCreates and examines partitions and partition tables (GPT/MBR).
e2fsckChecks and repairs ext2/ext3/ext4 filesystems.
tune2fsTunes parameters of an ext filesystem and shows its information.
dhcpdDHCP server: hands out IP addresses automatically to the machines on a network. With -t it only validates the config.
dhclientDHCP client: asks the server for an address and configures the interface with it.
dhcp-lease-listLists the leases handed out by the DHCP server: MAC, IP and hostname.
named-checkconfChecks that the BIND configuration (named.conf and its includes) is correct. Prints nothing if OK.
named-checkzoneValidates a DNS zone file: checks that it has SOA and NS and that the syntax is correct.
apachectlControls and checks Apache. With configtest it validates the config and with -S it lists the virtual hosts.
nginxNginx web server. With -t it checks the config and with -s reload it reloads without downtime.
a2ensiteEnables an Apache site (virtual host) by creating the link in sites-enabled.
a2dissiteDisables an Apache site (virtual host) by removing the link from sites-enabled.
testparmChecks that the Samba configuration (smb.conf) is valid and shows the shared resources.
smbpasswdManages Samba user passwords (with -a it adds one).
smbclientSamba client: lists shares (-L) or connects to a shared folder.
exportfsShows or reloads the directories NFS shares (defined in /etc/exports).
showmountShows which directories an NFS server is exporting (-e to list them).
postfixMail transfer agent (MTA). With check it validates the config and with status it tells if running.
mailSends an email from the command line (with -s the subject).
mailqShows the system mail queue (messages pending delivery).
sshdSSH server. With -t it checks the configuration file (/etc/ssh/sshd_config).
lpstatShows the status of CUPS printers (the default printer with -d).
lpSends a document to the printer (with -d you choose which one).
lpadminAdministers printers in CUPS: with -p and -v you add a printer and its destination.
nanoSimple text editor in the terminal. Ideal to edit config files without hassle.
vimPowerful, fast text editor. It has several modes; you learn it with practice.
viThe classic Unix editor. Almost always vim is its modern version.
moreShows a file page by page, without scrolling through the text.
clearClears the terminal screen leaving the prompt at the top.
exitCloses the terminal session (or the script you are in).
helpShows help for the shell built-in commands.
testEvaluates a condition and returns success or failure. Used in scripts and with [ ].
hostnameShows or changes the machine name on the network.
lspciLists the devices on the PCI bus (cards, controllers...).
lsusbLists the devices connected over USB.
lsb_releaseShows the Linux distribution and its version. With -a, all the data.
iostatShows disk and CPU input/output statistics.
netstatShows network connections, open ports and routing tables (classic).
wallSends a message to every terminal of the logged-in users.
apt-getClassic Debian/Ubuntu tool to install and upgrade packages.
apache2ctlDebian version of apachectl: checks and controls the Apache server.
unaliasRemoves an alias you had defined earlier.
typesetLike declare: declares variables and their attributes (same as declare).
mkfsCreates a filesystem on a device (format). With -t you choose the type.
adduserCreates a new user account. With -m it builds the home folder and copies the base files; it prompts for the rest interactively.
ncNetcat, the network Swiss army knife: opens TCP/UDP connections, listens on a port and checks whether a port is open. It is invoked as nc or netcat.