Comprehensive reference for linux commands reference covering essential concepts, practical examples, and production best practices.
Linux Commands Reference
This reference page collects the Linux commands most frequently needed when working on production servers, staging environments, or local development boxes that run a Unix-like operating system. It matters whenever you need to inspect, troubleshoot, or modify a system without leaving a terminal: diagnosing performance issues, cleaning up disk space, verifying network connectivity, managing services, or reviewing process state. The content is organised around common administrative tasks rather than by command category, so you can find what you need based on what you’re trying to accomplish. Every command shown ships with standard Linux distributions; no proprietary tools or invented CLIs are used.
When you need to see what’s running, identify a rogue daemon, or kill a stuck job, the ps family and its companions are the first port of call.
ps aux – lists all processes for all users in BSD‑style output. The a flag shows processes for other users, u shows user/CPU time details, and x includes processes without a controlling terminal (daemons, workers). On systems where ps defaults to System V syntax, ps -ef provides an equivalent full‑listing.pgrep pattern – searches the process table for a matching pattern and prints matching PIDs. pgrep -x matches the entire name exactly; pgrep -f matches against the full command line.pkill pattern – sends a signal (default SIGTERM) to processes matching *pattern*. pkill -9 pattern forces SIGKILL. Use the -o flag to target only the oldest matching PID and -n for the newest.top – interactive real‑time view of process activity. Key interactive commands: M to sort by memory, P to sort by CPU, u <user> to filter by user, r <PID> to renice a process.htop – often not present on minimal installs; top is the portable alternative.Sharp edges: ps output format varies between distributions. On some systems ps aux may not exist or may require the procps package. The top binary may be replaced by htop or gotop in custom images, changing available key bindings. pgrep and pkill rely on exact binary name matching; a symlink or a script wrapper may not be found. kill <PID> without a signal number sends SIGTERM; daemons that ignore SIGTERM will survive, requiring kill -9 <PID> (SIGKILL) which bypasses cleanup handlers and may leave state files or sockets in an inconsistent condition.
Administrative file work—cleanup, migration, permission changes—relies on a small set of core utilities. Flags are portable across GNU and BSD variants, but behaviour differences exist.
rm -ri <path> – interactive removal. Each matching file prompts for confirmation. rm -rf <path> removes recursively without prompting; use with extreme care, especially with rm -rf / or rm -rf ~ edge cases.mv <src> <dst> – atomically moves or renames a file. If <dst> exists and is a directory, <src> is moved inside it. If <dst> is an existing regular file, it is overwritten without prompt unless rm -i or mv -i is used.cp -r <src_dir> <dst_dir> – recursive copy. cp -a preserves attributes (timestamps, permissions, ownership) and copies symlinks as symlinks. cp -r copies the contents of symlinks.find /path -name "pattern" -type f – locates files matching a name glob. -name is case‑sensitive on most Linux filesystems; use -iname for case‑insensitive matching. -type f restricts results to regular files; -type d for directories.find /path -mtime +30 – files modified more than 30 days ago. Combine with -exec rm {} \; for cleanup scripts, but be cautious of argument limits.du -sh /* – summaries total size of each top‑level mount point. du -h /var/log gives human‑readable totals for a single directory. du -sh * inside a directory sums each immediate child.df -h – displays filesystem disk space availability in human‑readable form. df -Th shows filesystem type alongside usage.Sharp edges: find pathnames containing spaces or special characters require proper quoting or -print0 paired with xargs -0 to avoid word‑splitting. rm -rf on a symlink removes the symlink target only if the target is not itself a directory being held open by another process. mv across filesystems copies then deletes the original, which can be slow and may lose extended attributes unless rsync -a is used instead. chmod 777 grants world‑readable/writable/executable; on multi‑user systems this often opens security gaps, and many sites enforce umask policies that silently override the explicit mode.
Verifying that a service is reachable, checking interface configuration, or debugging DNS resolution are routine tasks.
ip addr show dev <interface> – displays interface addresses, MTU, and state. ip -br addr gives a brief one‑line per interface summary. ip link show lists data‑link layer state.ping -c 4 <host> – sends four ICMP echo requests. The -c flag limits count; without it ping runs forever. ping -s <size> sets payload size, useful for MTU probing.nc -zv <host> <port> – netcat “zero‑I/O” mode: probes the port without sending data (-z), shows open/closed state (-v). Effective for quick port checks without establishing a full connection.curl -I <url> – fetches only the HTTP headers for a URL. Useful for checking server software, Content‑Type, Last‑Modified, or response codes without downloading the body.traceroute -n <host> – traces the route packets take, skipping DNS resolution with -n for faster output and numeric IP display.ss -tlnp – lists all TCP sockets in listening state, showing process IDs (-p) and numerical addresses (-n). Replaces the deprecated netstat -tlnp on most modern distributions.Sharp edges: ping requires no special privileges on Linux, but many ICMP filters in cloud environments or corporate firewalls silently drop echo requests, making a “no‑response” result ambiguous—it may indicate filtering rather than host unavailability. nc -zv can report a port as “open” if the kernel’s SYN‑ACK arrives before the application accepts the connection, which may not reflect the final service state. curl -I may still trigger a full request body download if the server redirects (301/302) or enforces HSTS; adding --max-time 5 bounds the wait. traceroute relies on ICMP time‑exceeded messages; some networks rate‑limit ICMP, causing incomplete traces or all‑star results. ss output may be truncated for very long command lines; ps -p <PID> -o args= can supplement it.
Managing who can do what, and under which account a process runs, is central to system security and operations.
whoami – prints the effective user name of the current shell.id – effective and real UID/GID and all supplementary group IDs. id <username> shows the same for any user.groups <username> – lists all groups a user belongs to.chmod <mode> <file> – changes file permissions. Symbolic modes (u+rwx, go-rwx) are less error‑prone than octal modes for ad‑hoc changes. chmod 644 sets rw‑r--r--; chmod 755 sets rwxr-xr-x.chown <user>:<group> <file> – changes owner and group. chown root:root is common for binaries that must run as root via sudo or set‑uid. chown :<group> changes only the group.sudo <command> – executes *command* as the target user (default root) with a time‑stamped ticket. sudo -v extends the ticket timeout without running a command; sudo -k invalidates it immediately.visudo – edits the sudoers file in a safe editor mode, checks for syntax errors before installation, and prevents concurrent edits that could lock out all privilege escalation.Sharp edges: chmod on symbolic links only affects the link itself, not the target; chmod +x on a symlink to a script does not make the script executable if the target lacks the shebang or execute bit. sudo timestamp is per‑terminal; opening a new shell or waiting more than the default 5‑minute timeout requires re‑authentication (sudo -k then sudo). chown on directories with setgid bit set forces new files and subdirectories to inherit the group, but this behaviour does not apply to existing files—only newly created ones. visudo will refuse to save if the file contains unescaped % characters or mismatched Cmnd_Alias definitions, potentially locking out all sudo access until manually repaired.
Controlling long‑running processes, checking logs, and ensuring services start at boot are daily operations.
systemctl start <service> – activates a unit file immediately. systemctl restart <service> stops and starts atomically. systemctl stop <service> deactivates it.systemctl status <service> – shows whether the unit is active, idle, failed, or inactive, along with the most recent log entries from the journal.systemctl enable <service> – creates the symlinks required for the service to start at boot in the default target. systemctl disable <service> removes those symlinks.systemctl daemon-reload – rereads all unit files from disk. Required after manually creating or modifying unit files in /etc/systemd/system/ or /lib/systemd/system/.journalctl -u <service> – streams the journal entries for a specific unit. journalctl -u <service> --since "30 minutes ago" filters by time. journalctl -f <service> follows new entries in real time.systemctl mask <service> – creates a symlink pointing to /dev/null, making the unit permanently unstartable (even manually). Useful for preventing a conflicting service from running.Sharp edges: systemctl operations are serialized through the system manager; if the manager is in a degraded state (e.g., disk full, journal corrupted), start/restart may silently fail and report activating indefinitely. journalctl disk usage grows unboundedly unless SystemMaxUse= is set in /etc/systemd/journald.conf; a saturated journal can prevent new entries from being written, masking service failures. systemctl mask is irreversible without manually removing the mask symlink and running daemon-reload; it is often used in container or immutable‑image workflows to disable unwanted daemons, but mistakenly masking a required system unit (e.g., networkd) can take the network offline until the mask is removed. daemon-reload after editing a unit file does not restart running instances; a manual restart is needed for changes to take effect.
find pathname handling: find / -name "*.log" works, but find / -name "*.log" -print0 | xargs -0 ls is required for paths with spaces, newlines, or glob‑special characters. Omitting the null‑delimiter causes xargs to split on whitespace, potentially deleting or acting on wrong files.xargs argument limit: xargs on most Linux distributions caps the command line at 125 KB (confirmed by getconf ARG_MAX). A find -exec rm {} \; on a directory with millions of tiny files may hit this limit, causing argc too large errors. Using find -delete or find ... -print0 | xargs -0 -n 500 rm mitigates it.grep -r in binary files: grep -r "pattern" . will, by default, print Binary file matches without showing matching lines. Adding -a treats all files as text (risky for large binaries) or --include='*.log' limits scope. grep --mmap may improve speed but can cause segmentation faults on certain filesystems or with huge files.dd source/destination swap: dd if=/dev/sdb of=/dev/sda copies from *sdb* to *sda*. Reversing the arguments wipes the target disk. There is no confirmation prompt beyond the final summary line (X+0 records in, Y+0 records out). Many recovery‑focused admins add conv=sync,noerror only after exhaustive testing, never in production without a verified backup.cron environment: cron does not source /etc/profile or ~/.bashrc. PATH, language settings, and shell functions available in an interactive shell are absent. Always use absolute paths in cron jobs, or explicitly set SHELL=/bin/bash and PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin at the top of the crontab.nohup vs & vs disown: nohup <cmd> & redirects stdout/stderr to nohup.out and detaches from the terminal. cmd & merely backgrounds the process; closing the terminal kills it unless disown -h <PID> is used afterwards. disown removes the job from the shell’s job table entirely, which is useful when you’ve already backgrounded a process and forgot to use nohup.kill signal defaults: kill <PID> sends SIGTERM (15). Many daemons handle SIGTERM gracefully, performing cleanup and exiting. kill -9 <PID> (SIGKILL) cannot be caught or ignored; the process is immediately terminated, which may leave temporary files, half‑written sockets, or inconsistent database states. Always prefer SIGTERM first, verify the process exited, then use SIGKILL only if necessary.systemd unit file ordering: unit names with higher alphabetical order may start before dependencies are ready if WantedBy= and Requires= are not correctly paired. A common failure mode is a service reporting dependency or start‑postponed because a network.target or local-fs.target unit was not pulled in. Checking systemctl list-dependencies <service> reveals the full pull‑in tree.This page was rewritten on 14 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy