LINUX & BASH SHELL COMMAND REFERENCE
An offline-first search index for standard Unix commands, permission mappings, text stream pipelines, redirection rules, and process automation syntax.
File System Operations8 ENTRIES
List directory contents. Often used with flags to see hidden files or file details.
ls [flags] [directory]ls -la /var/logRunning ls in a folder with millions of files without pagination or limit, causing the terminal output buffer to freeze.
Change the shell working directory to a specified path.
cd [directory]cd /var/www/html
cd .. # Go up one level
cd ~ # Go to home directoryUsing 'cd' inside an automated shell script without checking if the target directory exists, leading to subsequent commands executing in the wrong folder.
Print name of current/working directory.
pwdpwdConfusing the current working directory in script execution with the directory where the script file is located.
Create one or more new directories.
mkdir [flags] <directory_name>mkdir -p project/src/components # Creates nested folders if they do not existAttempting to create nested directories without the '-p' flag, resulting in a 'No such file or directory' error.
Copy files and directories from source to destination.
cp [flags] <source> <destination>cp config.env.example config.env
cp -R src/ backup/src_backup/ # Recursive copyForgetting the '-R' or '-r' flag when copying directories, which silently ignores folders or throws an error.
Move or rename files and directories.
mv <source> <destination>mv oldname.txt newname.txt
mv file.txt /tmp/trash/Accidentally overwriting an existing file at the destination. Use the '-n' flag to prevent overwriting or '-i' for interactive confirmation.
Remove files or directories. Use recursive flag to delete folders.
rm -rf <path>rm -rf ./tmp/cacheRunning 'rm -rf /' or omitting path configurations, which can permanently wipe out the system filesystem.
Search for files in a directory hierarchy based on names, types, sizes, or dates.
find [path] -name "<pattern>"find . -type f -name "*.log" -mtime -7Forgetting to wrap the name pattern in quotes, which causes the shell to expand the glob pattern locally before running find.
File Permissions2 ENTRIES
Change the access permissions of files or directories (read, write, execute).
chmod [permissions] <file>chmod 755 script.sh
chmod +x deploy.shSetting 'chmod 777' on files in production, which gives global write and execute access, creating severe security vulnerabilities.
Change file owner and group ownership of files and directories.
chown [owner]:[group] <file>chown -R www-data:www-data /var/www/htmlForgetting the -R flag when you want to change ownership for all nested files and subdirectories.
Pipelines & Redirection2 ENTRIES
Redirect command standard output (stdout) or standard error (stderr) to a file or stream.
<command> > file.txt 2>&1
# Append stdout:
<command> >> file.txtnpm run start > output.log 2>&1 &Using '>' when you mean to append. '>' will overwrite the file entirely, destroying previous logs. Use '>>' to append.
Build and execute command lines from standard input (useful for chaining output files to arguments).
find . -name "*.tmp" | xargs rmcat ips.txt | xargs -I {} ping -c 1 {}Forgetting that xargs splits on spaces/newlines, which can fail or cause issues if filenames contain spaces. Use 'find -print0 | xargs -0' to solve this.
Process Control4 ENTRIES
Report a snapshot of current running processes in the system.
ps [flags]ps aux | grep nodeRunning ps without proper flags and assuming a process isn't running, when it's actually running under a different user or session.
Send a signal to a process (usually to terminate or kill it by PID).
kill [-signal] <pid>kill -9 12345Using 'kill -9' (SIGKILL) immediately. Always try 'kill -15' (SIGTERM) first to allow the process to clean up connection resources and write files.
Run a command immune to hangups, allowing background processes to continue running even after you log out of the SSH session.
nohup <command> > output.log 2>&1 &nohup node server.js &Forgetting to add '&' at the end, which keeps the process in the foreground instead of putting it into the background.
Interactive, real-time process monitoring display of system activity and resource consumption.
top
htophtopLeaving high-frequency monitoring tools like top running in multiple ssh terminals, which itself consumes non-trivial CPU cycles.
Text Processing & Searching6 ENTRIES
Search text for lines matching a pattern. Supports regular expressions.
grep [flags] <pattern> [file]grep -rn "error" /var/log/nginx/
grep -E "^[0-9]{1,3}\\." log.txtSearching large binary files or node_modules directories without excluding them, resulting in massive terminal outputs.
Stream editor for filtering and transforming text (e.g. search and replace).
sed 's/<search>/<replace>/g' <file>sed -i 's/PORT=3000/PORT=8080/g' .env # Modifies the file in-placeUsing '-i' (in-place modification) without first running sed without '-i' to preview and verify changes.
A versatile pattern scanning and processing language, highly useful for extracting columns from logs/command outputs.
awk '<pattern> {action}' [file]ps aux | awk '{print $2, $11}' # Prints PID and command columnsConfusing field separators (default is whitespace) when parsing CSV files without specifying '-F ","'.
Concatenate and display file contents in the terminal.
cat [file]cat /etc/nginx/nginx.confUsing 'cat' to view extremely large files (e.g., gigabyte log files), which floods the terminal buffer. Use 'less' or 'tail' instead.
Output the last part of files. Often used to watch logs in real-time.
tail [flags] <file>tail -f -n 100 /var/log/syslog # Follow logs as they growRunning 'tail -f' on log-rotated files; if the target file is renamed (rotated), tail might stop displaying new lines. Use '--follow=name' if supported.
Output the first part (lines) of files.
head -n <number_of_lines> <file>head -n 20 package.jsonOmitting the number of lines when you want to view a specific amount (default is 10 lines).
System Information & Disk Usage4 ENTRIES
Report filesystem disk space usage for all mounted drives.
df [flags]df -h # Human-readable format (MB/GB)Ignoring disk space consumption alerts and failing to inspect inode exhaustion ('df -i'), which can freeze systems even if disk space is free.
Estimate file space usage recursively for directories.
du [flags] [path]du -sh * # Show total size of each file/folder in current directoryRunning raw 'du' on the root directory `/` without limiting depth or using '-h', causing endless screens of details.
Display amount of free and used physical memory (RAM) and swap in the system.
free [flags]free -h --siMisinterpreting the 'available' memory. Linux utilizes unused RAM for buffers/cache; look at 'available' rather than 'free' to gauge actual capacity.
Print system kernel, OS, and machine architecture details.
uname [flags]uname -a # Print all system detailsAssuming all architectures are the same and downloading incompatible binaries (e.g. x86_64 vs arm64).
Network & Connectivity5 ENTRIES
Transfer data from or to a server using supported protocols (HTTP, HTTPS, FTP, etc.).
curl [flags] <url>curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' https://api.example.com
curl -o app.tar.gz https://example.com/app.tar.gzRunning curl on HTTPS sites with expired/invalid certificates using '-k' (insecure) flag in production environments, exposing traffic to MITM attacks.
Non-interactive network downloader. Great for downloading files recursively.
wget [flags] <url>wget -c https://example.com/largefile.zip # Resume partial downloadUsing wget to pull files without limiting retry counts or timeouts on flaky networks, resulting in hung automation scripts.
Send ICMP Echo requests to verify host connectivity.
ping [flags] <host>ping -c 4 google.com # Stop after sending 4 packetsRunning ping without pack count limit on Linux systems, which will ping infinitely until manually interrupted with Ctrl+C.
Open a secure cryptographic network protocol for operating network services securely over an unsecured network.
ssh [flags] [user]@hostssh -i ~/.ssh/key.pem ubuntu@192.168.1.50
ssh -p 2222 root@example.comLeaving default port 22 exposed to the public internet without SSH key-only authentication, inviting brute force botnets.
Securely copy files or directories between a local and remote host or between two remote hosts.
scp [flags] <source> <destination>scp -i key.pem ./build.zip ubuntu@192.168.1.50:/var/www/
scp -r user@remote:/var/log/nginx/ ./local_logs/Using scp recursively ('-r') for directories containing symlinks; it may result in infinite loops or duplicate copies. Use tar over ssh instead.
Archiving & Compression2 ENTRIES
Archiving utility to bundle multiple files into a single archive file (often compressed).
tar [flags] <archive_name> [files_or_directories]tar -czvf archive.tar.gz ./folder # Compress
tar -xzvf archive.tar.gz # DecompressForgetting to specify the '-f' (file) flag at the very end of options (e.g. doing 'tar -cfzv'), which causes tar to try to write to a file named 'z'.
Package and compress or extract zip format archives.
zip -r <archive_name>.zip <folder>
unzip <archive_name>.zip -d <destination_dir>zip -r backup.zip ./data
unzip dist.zip -d /var/www/html/Running zip without the '-r' flag on folders, resulting in an empty zip archive that contains only the parent directory metadata.