Why Learn Linux Commands?
The Linux command line is one of the most powerful tools available to any computer user. Whether you're managing files, monitoring system resources, or automating repetitive tasks, knowing your way around the terminal makes you dramatically more productive. This reference guide covers the most important Linux commands grouped by category.
File and Directory Navigation
pwd— Print working directory (shows your current location).ls— List directory contents. Usels -lafor detailed view including hidden files.cd /path/to/dir— Change directory. Usecd ~for home,cd ..to go up one level.find / -name "file.txt"— Recursively search for files by name.locate filename— Fast file search using a pre-built index (requiresupdatedb).
File Operations
cp source dest— Copy files or directories (-rflag for directories).mv source dest— Move or rename files and directories.rm file— Remove a file. Userm -rf dir/to remove directories recursively (use with caution).mkdir dirname— Create a new directory. Usemkdir -p a/b/cto create nested directories.touch file.txt— Create an empty file or update a file's timestamp.ln -s target link— Create a symbolic (soft) link.
Viewing and Editing Files
cat file.txt— Output file contents to the terminal.less file.txt— View file contents page by page (pressqto quit).head -n 20 file.txt— Show the first 20 lines of a file.tail -n 20 file.txt— Show the last 20 lines. Usetail -fto follow live log output.nano file.txt— Simple terminal text editor, great for beginners.vim file.txt— Powerful modal text editor (pressito insert,:wqto save and quit).
Text Processing
grep "pattern" file— Search for a pattern in a file. Use-rfor recursive search in directories.grep -i "error" /var/log/syslog— Case-insensitive search in log files.awk '{print $1}' file— Process and extract columns from text.sed 's/old/new/g' file— Find and replace text in a file.sort file.txt— Sort lines alphabetically. Use-nfor numeric sort.uniq— Remove duplicate consecutive lines (often paired withsort).wc -l file.txt— Count lines in a file. Use-wfor words,-cfor bytes.
System Information and Monitoring
uname -a— Show kernel version and system architecture.toporhtop— Interactive process viewer showing CPU and memory usage.df -h— Show disk space usage in human-readable format.du -sh /path/— Show disk usage of a specific directory.free -h— Display RAM and swap usage.uptime— Show how long the system has been running and load averages.lscpu— Show detailed CPU information.
Process Management
ps aux— List all running processes with details.kill PID— Send a termination signal to a process by its ID.kill -9 PID— Force-kill a process immediately.pkill processname— Kill a process by name.bg/fg— Resume a job in the background or foreground.nohup command &— Run a command immune to hangups, in the background.
Networking
ping hostname— Test network connectivity.curl -O https://example.com/file— Download a file from the web.wget https://example.com/file— Another popular download tool.ss -tulnp— Show listening ports and their associated processes.ip addr— Show network interfaces and IP addresses.
Putting It All Together
The real power of the Linux command line comes from combining these commands using pipes (|) and redirection (>, >>). For example: ps aux | grep nginx | grep -v grep shows all nginx processes. The more you practice, the more intuitive these commands become. Keep this guide handy as a reference and try each command in a safe test environment.