Linux Terminal Commands & Shortcuts

Navigate your system like a pro. A curated list of essential bash commands for developers, system administrators, and DevOps engineers.

File System

ls
Ex: ls -lah
List files (Show hidden, human-readable size)
cd
Ex: cd ../dir
Change directory (Relative path)
pwd
Ex: pwd
Print working directory (Show current path)

File Operations

cp
Ex: cp -r src dest
Copy directory recursively
mv
Ex: mv old new
Move or Rename file
rm
Ex: rm -rf dir
Remove directory force (Careful!)
mkdir
Ex: mkdir -p path/to
Make directory (Create parents if needed)
touch
Ex: touch file.txt
Create empty file or update timestamp

Reading

cat
Ex: cat file.txt
Print file content to stdout
less
Ex: less file.txt
View large file content with pagination
head
Ex: head -n 5 file
Show first 5 lines of a file
tail
Ex: tail -f log.txt
Watch file changes in real-time (Follow)

Search

grep
Ex: grep -r "text" .
Search text recursively in directory
find
Ex: find . -name "*.js"
Find files by name in current dir

Permissions

chmod
Ex: chmod +x file
Make file executable
chown
Ex: chown user:group file
Change file ownership

System

ps
Ex: ps aux
Show all running processes
top
Ex: top
Real-time process monitor
kill
Ex: kill -9 <pid>
Force kill a process by ID
df
Ex: df -h
Show disk space usage (Human readable)
du
Ex: du -sh .
Show size of current directory

Archive

tar
Ex: tar -czvf arch.tar.gz .
Compress directory into tarball
unzip
Ex: unzip file.zip
Extract zip archive

Network

ssh
Ex: ssh user@host
Secure Shell remote login
curl
Ex: curl -I https://site.com
Check HTTP headers
wget
Ex: wget https://site/file.zip
Download file from web

⌨️ Essential Keyboard Shortcuts

Ctrl + C
Kill current process (SIGINT)
Ctrl + Z
Suspend process (Background)
Ctrl + L
Clear terminal screen
Ctrl + R
Search history (Reverse)
Alt + .
Paste last argument
Tab
Auto-complete path

The Complete Guide to Linux Terminal Mastery

The Linux command line is one of the most powerful interfaces ever created for interacting with a computer. While graphical user interfaces have their place, the terminal offers unparalleled speed, precision, and automation capabilities that no GUI can match. Whether you are managing a single development machine or orchestrating thousands of cloud servers, fluency with the terminal is an essential skill for any technology professional.

This guide covers the commands that form the foundation of Linux system administration. Each command represents decades of Unix philosophy refined into a single, focused tool. Understanding how these tools work individually—and more importantly, how they work together—will transform you from a casual user into a confident system administrator.

The Philosophy of Unix Commands

Unix and Linux commands are designed around a simple philosophy: each program should do one thing and do it well. The ls command lists directory contents—that is all it does, but it does it exceptionally well with dozens of options for different output formats. The grep command searches for patterns in text—nothing more, nothing less.

The power comes from combining these simple tools using pipes and redirection. The pipe character | takes the output of one command and feeds it as input to another. For example, ls -la | grep .js lists all files and then filters to show only JavaScript files. cat access.log | grep "404" | wc -l reads a log file, filters for 404 errors, and counts how many occurred. These chains can grow arbitrarily complex, creating powerful data processing pipelines without writing a single script.

File System Navigation

The Linux file system is a hierarchical tree rooted at /. Unlike Windows with its drive letters (C:, D:), everything in Linux exists under this single root. Understanding the standard directory structure is essential: /home contains user directories, /etc holds configuration files, /var stores variable data like logs, and /usr contains user programs.

Navigation commands are the most frequently used in any terminal session. pwd (print working directory) shows your current location, cd changes your location, and ls shows what is in a directory. Master the shortcuts: cd ~ goes to your home directory, cd - goes to your previous directory, and cd .. moves up one level.

The ls command's flags are worth memorizing. -l shows detailed information including permissions, ownership, size, and modification time. -a shows hidden files (those starting with a dot). -h displays sizes in human-readable format (KB, MB, GB). The combination ls -lah is probably the most common invocation.

File Manipulation

File operations in Linux require precision because there is no trash can by default—deleted files are gone immediately. The cp command copies files, mv moves or renames them, and rm removes them. For directories, always remember the -r (recursive) flag: cp -r folder1 folder2 copies a directory and all its contents.

The infamous rm -rf command deserves special attention. It removes directories recursively and forcefully, without any confirmation prompts. This is dangerous because a typo like rm -rf / home (with an accidental space) can attempt to delete your entire system. Always double-check your commands, especially when using rm with wildcards or as root.

Creating files and directories is straightforward: touch creates empty files (or updates timestamps of existing files), and mkdir creates directories. The -p flag for mkdir is incredibly useful—it creates parent directories as needed, so mkdir -p projects/2024/client/src creates the entire path even if none of those directories exist.

Viewing and Editing Files

Linux provides multiple commands for viewing file contents because different situations call for different tools. cat prints an entire file to the terminal—great for short files but overwhelming for long ones. less is a pager that lets you scroll through files, search with /, and quit with q. head and tail show the beginning and end of files, respectively.

The tail -f command deserves special mention. The -f flag means "follow"—the command does not exit but continues to display new lines as they are written to the file. This is indispensable for monitoring log files in real-time. For example, tail -f /var/log/nginx/access.log shows each new request as it comes in.

For editing files directly in the terminal, you will need to learn a text editor. nano is beginner-friendly with on-screen hints for all commands. vim is far more powerful but has a notoriously steep learning curve. At minimum, learn how to exit vim (press Escape, then type :q! to quit without saving or :wq to save and quit).

Searching and Finding

grep is the Swiss Army knife for searching text. At its simplest, grep "pattern" file.txt finds lines containing the pattern. Add -r for recursive searching through directories, -i for case-insensitive matching, -n to show line numbers, and -v to invert the match (show lines that do NOT contain the pattern).

find locates files based on various criteria beyond just name. You can search by type (-type f for files, -type d for directories), by size (-size +10M for files larger than 10 megabytes), by modification time (-mtime -7 for files modified in the last week), or by permissions. The -exec flag allows you to run commands on found files.

Permissions and Ownership

Linux file permissions control who can read, write, and execute files. Each file has three permission sets: owner, group, and others. The chmod command changes permissions using either symbolic notation (chmod +x script.sh adds execute permission) or numeric notation (chmod 755 script.sh sets rwxr-xr-x).

Understanding the numeric notation is valuable. Each digit represents a permission set (owner, group, others), and each digit is the sum of read (4), write (2), and execute (1). So 755 means owner has 7 (4+2+1 = rwx), group has 5 (4+1 = r-x), and others have 5 (r-x).

The chown command changes file ownership. Only root can change file ownership, so you typically use sudo chown user:group file. This is essential when deploying web applications where files might be owned by your user but need to be readable by the web server's user (like www-data for Nginx).

Process Management

Knowing how to manage running processes is crucial for system administration. ps aux shows all running processes with detailed information. top provides a real-time, updating view of processes sorted by CPU or memory usage—press q to exit. The more modern htop (usually needs to be installed) provides an easier-to-read interface with mouse support.

To stop a process, you need its PID (process ID), which you can find from ps or top. The kill command sends signals to processes. kill PID sends SIGTERM, asking the process to terminate gracefully. kill -9 PID sends SIGKILL, which forcefully terminates the process without giving it a chance to clean up—use this only when a process is truly stuck.

Disk and System Information

df -h shows disk space usage for all mounted filesystems in human-readable format. du -sh directory shows the total size of a directory. free -h displays memory usage. uptime shows how long the system has been running and the load averages.

These commands are essential for monitoring system health. When a server starts behaving slowly, checking disk space (df), memory (free), and CPU load (top) will usually reveal the bottleneck. A full disk is one of the most common causes of mysterious server problems, as applications fail to write logs or temporary files.

Network Commands

ssh is how you connect to remote servers. The basic syntax is ssh user@hostname. Once connected, you can run commands on the remote machine as if you were there physically. SSH keys provide secure, passwordless authentication—generate them with ssh-keygen and copy to the server with ssh-copy-id.

curl and wget are command-line tools for HTTP requests. curl -I URL fetches just the headers, useful for checking redirects and caching. wget URL downloads files. curl is more versatile for API testing, supporting various HTTP methods, custom headers, and POST data.