Command Line Cheat Sheet
A practical reference for navigating files, inspecting processes, permissions, disk usage, and everyday terminal work.

The command line is fastest when the commands you use regularly are easy to find and safe to apply. This reference keeps the everyday operations in one place.
Commands that delete files, change ownership, or stop processes can cause data loss or downtime. Check the resolved path, process ID, and current directory before running them—especially with
sudo,-r, or-f.
Navigate directories
Print the current directory:
pwdMove into a directory, return to its parent, or go back to the previous directory:
cd folder_name
cd ..
cd -List files, including hidden entries:
ls -laCreate a directory and any missing parents:
mkdir -p path/to/folderWork with files
Copy or move a file:
cp source.txt destination.txt
mv old-name.txt new-name.txtCopy a directory recursively:
cp -R source_folder target_folderRemove a file:
rm file_nameRemove a directory recursively only after verifying the exact path:
rm -r path/to/folderUse rm -rf only when you deliberately need non-interactive forced removal. It bypasses useful safeguards and deserves a second path check.
Read a file or follow an actively written log:
cat file_name
tail -f path/to/application.logEmpty a log file without replacing it:
truncate -s 0 path/to/application.logInspect disk usage
Show the total size of a directory and the size of its immediate children:
du -sh path/to/folder
du -sh path/to/folder/*Show filesystem capacity in a human-readable format:
df -hPermissions and ownership
Use symbolic modes when the intent matters more than the numeric representation:
chmod u+x script.sh
chmod -R u+rwX,go-rwx private-folderChange ownership for a known user and group:
sudo chown user_name:group_name file_name
sudo chown -R user_name:group_name path/to/folderAvoid applying recursive permissions to broad or unresolved paths.
Processes and ports
Find a process listening on a port:
lsof -nP -iTCP:3000 -sTCP:LISTENAsk a process to stop gracefully before forcing it:
kill process_id
kill -9 process_idSIGKILL (-9) gives the process no chance to clean up. Treat it as the fallback, not the default.
Services
On a systemd-based Linux host, inspect and restart a service:
sudo systemctl status service_name
sudo systemctl restart service_nameService names and management tools differ across operating systems, containers, and hosting platforms. Verify the runtime before copying a production command.
Make commands explainable
A useful cheat sheet records intent, not just syntax. Before keeping a command, note what it changes, how to verify the result, and whether it is reversible. That small habit turns a list of terminal fragments into an operational tool.