Linux Commands Cheat Sheet
The most essential Linux terminal commands for developers. Navigate files, search logs, and manage permissions with ease.
ls
Lists directory contents (files and folders).
Syntax
ls
ls -laExample
ls -laPro Tip
`ls -la` lists everything in a long format, including hidden files and file permissions.
Common Mistake
Forgetting the `-a` flag when trying to find hidden files like `.env` or `.git`.
cd
Changes the current working directory.
Syntax
cd <directory>Example
cd /var/www/html
cd ..Pro Tip
`cd ..` moves you up one directory. `cd -` moves you back to your previous directory.
Common Mistake
Using `cd /` instead of `cd ~/`. `/` is the root of the entire system, `~/` is the root of your user folder.
mkdir
Creates a new directory (folder).
Syntax
mkdir <folder-name>Example
mkdir my-new-project
mkdir -p src/components/uiPro Tip
Use `mkdir -p a/b/c` to create a deeply nested folder structure instantly.
Common Mistake
Trying to create nested folders without using the `-p` (parents) flag.
rm
Removes files or directories.
Syntax
rm <file>
rm -rf <directory>Example
rm old-file.txt
rm -rf node_modulesPro Tip
Always double-check your current directory (`pwd`) before running `rm -rf`.
Common Mistake
Running `rm -rf /` or deleting important directories. `rm -rf` deletes folders forcefully and recursively with no undo!
grep
Searches for a specific pattern of text within files.
Syntax
grep "search_string" <file>Example
grep "password" config.txt
grep -r "function()" .Pro Tip
Use `grep -r` to search recursively through all files in the current directory.
Common Mistake
Searching manually through giant log files instead of just using `grep`.
chmod
Changes the file permissions (read, write, execute).
Syntax
chmod <permissions> <file>Example
chmod +x script.sh
chmod 755 server.jsPro Tip
`chmod +x` is the easiest way to make a bash script executable.
Common Mistake
Not understanding the numeric values. (4 = read, 2 = write, 1 = execute).
curl
Transfers data from or to a server, typically used to test APIs from the terminal.
Syntax
curl <url>Example
curl https://api.example.com/health
curl -X POST https://api.example.com/dataPro Tip
Add the `-i` flag to see the HTTP response headers.
Common Mistake
Forgetting to wrap URLs with complex query parameters in quotes.