Essential Linux and Bash commands for files, permissions, processes, networking, and more.
The Linux command line is fast and powerful once you know the right commands. This cheat sheet groups the essential Linux and Bash commands by task so you can find what you need without leaving the terminal.
From navigating files to managing processes and networking, keep this page handy as a quick reference. Each command comes with a short description of what it does.
Navigation & Files
| Command | What it does |
|---|
pwd | Print the current working directory. |
ls -la | List all files, including hidden, with details. |
cd <dir> | Change to a directory. |
cd .. | Move up one directory. |
mkdir -p <path> | Create a directory, including parents. |
touch <file> | Create an empty file or update its timestamp. |
cp -r <src> <dest> | Copy files or directories recursively. |
mv <src> <dest> | Move or rename a file or directory. |
rm -rf <path> | Delete files/directories recursively (careful!). |
Viewing & Editing
| Command | What it does |
|---|
cat <file> | Print the entire contents of a file. |
less <file> | View a file one page at a time. |
head -n 20 <file> | Show the first 20 lines of a file. |
tail -f <file> | Follow a file as new lines are appended. |
nano <file> | Open a simple terminal text editor. |
Permissions & Ownership
| Command | What it does |
|---|
chmod +x <file> | Make a file executable. |
chmod 644 <file> | Set read/write for owner, read for others. |
chown user:group <file> | Change a file's owner and group. |
sudo <command> | Run a command with superuser privileges. |
Search & Text
| Command | What it does |
|---|
grep -r "text" . | Search recursively for text in files. |
find . -name "*.js" | Find files matching a pattern. |
wc -l <file> | Count the number of lines in a file. |
sort <file> | Sort the lines of a file. |
sed 's/a/b/g' <file> | Replace all occurrences of a with b. |
Process Management
| Command | What it does |
|---|
ps aux | List all running processes. |
top | Show live process and resource usage. |
kill <pid> | Send a termination signal to a process. |
kill -9 <pid> | Force-kill a process immediately. |
<command> & | Run a command in the background. |
Networking
| Command | What it does |
|---|
curl <url> | Transfer data from or to a URL. |
ping <host> | Test connectivity to a host. |
wget <url> | Download a file from the web. |
ssh user@host | Connect to a remote machine over SSH. |
netstat -tulpn | List listening ports and services. |
Archives & System
| Command | What it does |
|---|
tar -czf out.tar.gz <dir> | Create a gzip-compressed archive. |
tar -xzf file.tar.gz | Extract a gzip-compressed archive. |
df -h | Show disk space usage, human-readable. |
du -sh <dir> | Show the total size of a directory. |
free -h | Show memory usage, human-readable. |
Linux Commands Cheat Sheet FAQs
How do I make a file executable in Linux?
Run chmod +x filename to add the executable permission, then run it with ./filename.
What is the difference between kill and kill -9?
kill PID sends a graceful termination signal, letting the process clean up. kill -9 PID force-kills it immediately without cleanup — use it only when a process is unresponsive.
How do I search for text inside files?
Use grep -r "text" . to search recursively through all files in the current directory and its subdirectories.
How do I check disk space usage?
Run df -h for overall disk usage per filesystem, or du -sh directory to see the total size of a specific directory.
How do I extract a .tar.gz file?
Run tar -xzf file.tar.gz. The flags mean extract (x), gzip (z), and file (f).