Introduction: Why Learn the Linux Command Line?
The Linux command line—also known as the terminal, shell, or console—might look intimidating at first. A blinking cursor on a black screen. No buttons, no menus, no friendly icons.
But here's the secret: the command line is the most powerful tool in a Linux user's arsenal. Once you learn the basics, you'll work faster, automate repetitive tasks, and truly understand how your system operates.
Whether you're a developer deploying code, a sysadmin managing servers, or a curious tinkerer exploring your Raspberry Pi, this Linux command line cheat sheet will give you the essential commands you need to get started—and thrive.
Bookmark this page and keep it handy. Let's dive in.
2. File Operations: Create, Copy, Move, and Delete
Now that you can move around, let's manipulate some files and folders.
| Command | Description | Example |
|---|---|---|
touch | Create an empty file or update timestamp | touch newfile.txt |
mkdir | Create a new directory (folder) | mkdir projects |
cp | Copy a file or directory | cp file.txt /backup/ |
mv | Move or rename a file/directory | mv oldname.txt newname.txt |
rm | Remove (delete) a file | rm unwanted.txt |
rm -r | Remove a directory and all its contents (recursive) | rm -r old_projects/ |
rmdir | Remove an empty directory | rmdir empty_folder/ |
⚠️ Caution: There is no "Recycle Bin" in the Linux command line. When you rm something, it's gone. Double-check before hitting Enter!
3. Viewing and Editing Files
You'll often need to peek inside files or make quick edits without opening a full graphical editor.
| Command | Description | Example |
|---|---|---|
cat | Display the entire contents of a file | cat config.ini |
less | View a file page by page (press q to quit) | less longlog.txt |
head | Show the first 10 lines of a file | head -n 20 file.txt |
tail | Show the last 10 lines (great for logs) | tail -f /var/log/syslog (follow live) |
grep | Search for specific text inside a file | grep "error" app.log |
nano | Simple, beginner-friendly terminal text editor | nano script.sh |
vim | Powerful (but steep learning curve) editor | vim file.txt |
4. Permissions and Ownership
Linux is a multi-user system. Understanding permissions is crucial for security and avoiding "Permission Denied" errors.
| Command | Description | Example |
|---|---|---|
chmod | Change file permissions (read/write/execute) | chmod +x script.sh (make executable) |
chmod 755 | Set specific numeric permissions (rwxr-xr-x) | chmod 755 folder/ |
chown | Change file owner and group | chown user:group file.txt |
sudo | Execute a command with superuser (root) privileges | sudo apt update |
5. Process Management
Need to see what's running or force-close a frozen program? These commands give you control.
| Command | Description | Example |
|---|---|---|
ps | Display currently running processes | ps aux (show all processes for all users) |
top / htop | Interactive process viewer (real-time updates) | top (press q to quit) |
kill | Terminate a process by ID (PID) | kill 1234 |
kill -9 | Force-kill a stubborn process (SIGKILL) | kill -9 1234 |
bg / fg | Send a process to background / bring to foreground | bg (after Ctrl+Z) |
jobs | List background jobs in the current shell | jobs |
6. System Information and Monitoring
Check disk space, memory usage, and hardware details with these handy commands.
| Command | Description |
|---|---|
df -h | Show disk usage in human-readable format (GB/MB) |
du -sh * | Show size of files/folders in current directory |
free -h | Display available and used memory (RAM) |
uname -a | Show kernel version and system architecture |
lsb_release -a | Show which Linux distribution you're running (Ubuntu, Debian, etc.) |
uptime | How long the system has been running and load average |
whoami | Display the current logged-in username |
7. Networking Commands
Troubleshoot internet connectivity or download files directly from the terminal.
| Command | Description | Example |
|---|---|---|
ping | Test connectivity to a remote server | ping google.com |
ifconfig / ip a | Display network interface information (IP address, MAC) | ip a |
wget | Download a file from the internet | wget https://example.com/file.zip |
curl | Transfer data from/to a server (APIs, downloads) | curl https://api.example.com |
ssh | Securely connect to a remote Linux server | ssh user@192.168.1.100 |
scp | Securely copy files between local and remote | scp file.txt user@server:/path/ |
8. Package Management (apt, yum, dnf)
Installing software on Linux is done through package managers. The command differs slightly based on your distribution.
| Distribution | Command | Description |
|---|---|---|
| Debian/Ubuntu | sudo apt update | Refresh list of available packages |
| Debian/Ubuntu | sudo apt upgrade | Upgrade all installed packages |
| Debian/Ubuntu | sudo apt install [name] | Install a new package (e.g., sudo apt install htop) |
| Debian/Ubuntu | sudo apt remove [name] | Uninstall a package |
| RHEL/Fedora/CentOS | sudo dnf update (or yum) | Update packages |
| RHEL/Fedora/CentOS | sudo dnf install [name] | Install a package |
9. Terminal Shortcuts and Productivity Tips
Speed up your workflow with these keyboard tricks.
Ctrl + C– Kill the currently running command/programCtrl + Z– Suspend the current process (usebgto background it)Ctrl + D– Exit the current shell or send EOF (End of File)Ctrl + L– Clear the terminal screen (same as typingclear)Ctrl + R– Search through command history (type to find a previous command)Tab– Auto-complete file and folder names (press twice to see all options)Up Arrow– Cycle through previous commands!!– Run the last command again (useful withsudo !!)history– View a list of all recently used commandsalias– Create a shortcut for a long command (e.g.,alias ll='ls -la')
10. Frequently Asked Questions (FAQ)
1. What is the difference between the terminal and the shell?
The terminal is the window or application you type into (the interface). The shell (like Bash, Zsh, or Fish) is the program that actually interprets your commands and communicates with the operating system kernel.
2. How do I get help for a specific command?
Use the man (manual) command followed by the command name. For example: man ls. You can also often use the --help flag: ls --help.
3. I accidentally deleted a file with rm. Can I recover it?
Generally, no. The Linux rm command bypasses the Trash/Recycle Bin. Recovery is extremely difficult and requires specialized forensic tools. This is why backups and careful typing are essential!
4. What does "Permission Denied" mean?
It means your current user account doesn't have the rights to read, write, or execute that file or folder. To fix it, either change the permissions with chmod or use sudo to run the command as the root user (administrator).
5. How do I find where a program is installed?
Use the which command. For example, which python3 will show you the full path to the Python executable. You can also use whereis for broader search results.
6. What is the root user?
Root is the superuser account with unrestricted access to all commands and files. It's like "Administrator" on Windows. Using sudo temporarily grants you root privileges for a single command without logging in as root permanently (which is a security risk).
Comments