Basic Linux Commands & Help
A quick-reference cheatsheet of common Linux commands, grouped by category — search or filter to find what you need.
File & Directory
lsls [options] [path]List directory contents.
ls -lah /var/logcdcd [path]Change the current directory.
cd /etc/nginxpwdpwdPrint the current working directory.
cpcp [options] source destCopy files or directories.
cp -r ./site /var/www/sitemvmv source destMove or rename a file or directory.
mv old.conf new.confrmrm [options] pathRemove files or directories.
rm -rf /tmp/buildmkdirmkdir [-p] pathCreate a directory (with -p, create parents as needed).
mkdir -p /srv/app/logstouchtouch pathCreate an empty file, or update its modification time.
touch .envfindfind path -name patternSearch a directory tree for files matching criteria.
find /var/log -name '*.log' -mtime +7lnln [-s] target linkCreate a hard or (with -s) symbolic link.
ln -s /opt/app/current /opt/app/livetreetree [path]Show a directory's contents as a tree.
Permissions & Ownership
chmodchmod mode pathChange a file or directory's permissions.
chmod 640 /etc/app/secret.envchownchown user:group pathChange a file or directory's owner and group.
chown -R www-data:www-data /var/wwwumaskumask [mode]Show or set the default permission mask for new files.
chattrchattr +i pathChange extended file attributes, e.g. making a file immutable.
Process Management
psps [options]Show running processes.
ps aux | grep nginxtoptopLive view of running processes and resource usage.
htophtopInteractive, colorized alternative to top (not installed by default).
killkill [-signal] pidSend a signal (default TERM) to a process.
kill -9 4821killallkillall nameSend a signal to all processes matching a name.
killall -HUP nginxnicenice -n level commandRun a command with an adjusted scheduling priority.
nohupnohup command &Run a command immune to hangups, so it keeps running after logout.
jobsjobsList background jobs in the current shell.
bg / fgbg %1 / fg %1Resume a stopped job in the background or foreground.
Networking
pingping hostSend ICMP echo requests to test reachability.
ping -c 4 1.1.1.1curlcurl [options] urlTransfer data to/from a URL — the go-to tool for testing HTTP.
curl -I https://example.comwgetwget urlDownload a file from a URL.
ssss [options]Show socket statistics — the modern replacement for netstat.
ss -tulpnnetstatnetstat [options]Show network connections, routing tables, and interface stats (legacy).
digdig [@server] name [type]Query DNS records for a domain.
dig @1.1.1.1 example.com MXnslookupnslookup nameQuery DNS records (simpler, older alternative to dig).
traceroutetraceroute hostShow the network path (hops) to a host.
ipip addr | ip route | ...Show/manipulate routing, network devices, and addresses.
ip addr showsshssh user@hostOpen a secure shell session on a remote host.
rsyncrsync [options] source destEfficiently sync files/directories, locally or over SSH.
rsync -avz ./dist/ deploy@host:/var/www/app/ncnc host portNetcat — read/write raw TCP or UDP connections; handy for quick port tests.
Package Management
aptapt install|remove|update|upgrade pkgPackage manager for Debian/Ubuntu.
sudo apt update && sudo apt upgradeyum / dnfdnf install|remove pkgPackage manager for RHEL/CentOS/Fedora.
dpkgdpkg -i package.debInstall/query low-level .deb packages directly.
rpmrpm -ivh package.rpmInstall/query low-level .rpm packages directly.
snapsnap install pkgInstall sandboxed snap packages.
Disk & Storage
dfdf -hShow disk space usage per filesystem.
dudu -sh pathShow disk usage of files/directories.
du -sh /var/log/*mountmount device pathMount a filesystem.
umountumount pathUnmount a filesystem.
lsblklsblkList block devices (disks and partitions) as a tree.
fdiskfdisk -lPartition a disk, or list partitions with -l.
dddd if=in of=outLow-level copy of raw data between devices/files — powerful and unforgiving.
User Management
whoamiwhoamiPrint the current effective username.
idid [user]Show a user's UID, GID, and group memberships.
useradduseradd -m usernameCreate a new user account.
usermodusermod -aG group userModify an existing user account, e.g. adding a group.
usermod -aG docker deploypasswdpasswd [user]Change a user's password.
susu [-] [user]Switch to another user's shell.
sudosudo commandRun a command as another user (default root) per /etc/sudoers.
who / wwhoShow who is currently logged in.
Text Processing
grepgrep [options] pattern fileSearch text for lines matching a pattern.
grep -ri 'error' /var/log/app.logsedsed 's/find/replace/' fileStream editor for filtering and transforming text.
awkawk 'pattern {action}' filePattern-scanning and text-processing language.
awk '{print $1}' access.logcatcat filePrint a file's contents to stdout.
lessless fileView a file one screen at a time, scrollable.
head / tailtail -f fileShow the start/end of a file; -f follows new lines as they're written.
tail -f /var/log/syslogcutcut -d, -f1 fileExtract columns/fields from each line of a file.
sortsort [options] fileSort lines of text.
uniquniq [options] fileFilter out (or count) repeated adjacent lines — usually piped after sort.
wcwc -l fileCount lines, words, or bytes in a file.
diffdiff fileA fileBShow differences between two files.
xargscommand | xargs other-commandBuild and run commands from piped input.
find . -name '*.tmp' | xargs rmtartar -czf out.tar.gz dir/Archive files; -c create, -x extract, -z gzip, -f filename.
tar -xzf app.tar.gz -C /opt/appSystem Info
unameuname -aPrint system/kernel information.
uptimeuptimeShow how long the system has been running plus load averages.
freefree -hShow memory and swap usage.
vmstatvmstat [interval]Report virtual memory, CPU, and I/O statistics.
iostatiostat [interval]Report CPU and per-device I/O statistics (part of sysstat).
sarsar -ACollect and report historical system activity (part of sysstat).
dmesgdmesg | tailShow kernel ring buffer messages — useful for hardware/driver issues.
journalctljournalctl -u service -fQuery and follow the systemd journal (logs).
journalctl -u nginx -fhistoryhistoryShow this shell session's command history.
envenvShow the current environment variables.
systemd / Services
systemctl statussystemctl status serviceShow a service's current status.
systemctl start/stopsystemctl start|stop serviceStart or stop a systemd service.
sudo systemctl restart nginxsystemctl enablesystemctl enable serviceMake a service start automatically on boot.
systemctl daemon-reloadsystemctl daemon-reloadReload unit files after editing one, before restarting the service.
Archives & Compression
gzip / gunzipgzip file / gunzip file.gzCompress or decompress a single file.
zip / unzipzip -r out.zip dir/ / unzip out.zipCreate or extract a .zip archive.