
Essential Linux Commands
🐧 You'll Type These Commands Thousands of Times
Linux powers most web servers and dev environments. This cheatsheet covers the commands web developers use every day.
✅ Navigating the file system ✅ Working with files ✅ Searching and finding ✅ Permissions ✅ Processes ✅ Networking ✅ Package management ✅ SSH and remote access
#linux #commands #terminal #bash #cli #server #webdev #devops #coding #tips
Linux is the operating system behind most web servers, containers, and cloud infrastructure.
Knowing the related command line tools is essential for deploying and debugging web applications.
This cheatsheet provides a quick reference to the Linux commands web developers use most.
| Command | Description |
|---|---|
pwd | Print the current working directory. |
ls | List files and directories. |
cd | Change directory. |
mkdir | Create a directory. |
touch | Create an empty file or update its timestamp. |
cp | Copy files and directories. |
mv | Move or rename files and directories. |
rm | Delete files and directories. |
cat | Print the contents of a file. |
less | View a file page by page. |
head | Show the first lines of a file. |
tail | Show the last lines of a file, or follow it live. |
| Command | Description |
|---|---|
grep | Search for text patterns in files. |
find | Find files and directories by name or attributes. |
chmod | Change file permissions. |
chown | Change file ownership. |
ps | List running processes. |
kill | Stop a process by ID. |
top | Monitor processes and resource usage live. |
df | Show disk space usage. |
du | Show the size of files and directories. |
curl | Make HTTP requests from the terminal. |
ssh | Connect to a remote server. |
scp | Copy files between machines over SSH. |
Navigating the file system
Print the current directory.
pwdList files and directories.
lsList files and directories, including hidden files and details.
ls -laChange directory.
cd /var/www
cd .. # up one level
cd ~ # home directory
cd - # previous directoryWorking with files and directories
Create directories.
mkdir projectsCreate nested directories.
mkdir -p projects/app/srcCreate an empty file.
touch index.htmlCopy files and directories.
cp file.txt backup.txt
cp -r src/ dist/Move or rename files.
mv old-name.txt new-name.txt
mv file.txt /var/www/Delete files and directories.
rm file.txt
rm -r node_modules/Viewing files
Print an entire file.
cat config.jsonView a file page by page. Press q to quit.
less /var/log/syslogShow the first or last lines of a file.
head -n 20 app.log
tail -n 20 app.logFollow a log file live.
tail -f /var/log/nginx/access.logSearching and finding
Search for text inside files.
grep "TODO" app.jsRecusively search for text in a directory.
grep -r "apiKey" src/Search with case-insensitive matching.
grep -i "error" server.logFind files by name or type.
find . -name "*.test.js"
find /var/www -type d -name "uploads"Permissions
Change file ownership.
sudo chown www-data:www-data /var/www/htmlRecursively change ownership of a directory.
sudo chown -R $USER:$USER projects/Change file permissions.
chmod 644 index.htmlEach digit represents permissions for Owner, Group, and Others (in that order).
| Code | Binary | Symbolic | Permissions |
|---|---|---|---|
| 0 | 000 | --- | No permissions |
| 1 | 001 | --x | Execute only |
| 2 | 010 | -w- | Write only |
| 3 | 011 | -wx | Write + Execute |
| 4 | 100 | r-- | Read only |
| 5 | 101 | r-x | Read + Execute |
| 6 | 110 | rw- | Read + Write |
| 7 | 111 | rwx | Read + Write + Execute |
Examples:
| Value | Meaning |
|---|---|
644 | Owner reads/writes, others read. |
755 | Owner does everything, others read and execute. |
600 | Owner reads/writes only. |
You can use symbolic mode to add or remove permissions:
chmod +x deploy.sh| Symbol | Meaning |
|---|---|
| u | User/Owner |
| g | Group |
| o | Others |
| a | All (u+g+o) |
| + | Add permission |
| - | Remove permission |
| = | Set exact permission |
Examples:
| Command | Effect |
|---|---|
chmod u+x file | Add execute to owner |
chmod go-w file | Remove write from group & others |
chmod a=r file | Set read-only for all |
chmod u=rwx,go=rx file | Set 755 permissions |
chmod +x file | Add execute to all users |
chmod -x file | Remove execute from all users |
Processes
List running processes.
ps auxList processes and filter by name.
ps aux | grep nodeMonitor processes live. Press q to quit.
topStop a process.
kill 1234Stop a process forcefully.
kill -9 1234Disk usage
Show disk space on all file systems.
df -hShow the size of directories.
du -sh node_modules/
du -sh */Networking
Make an HTTP request.
curl https://api.example.com/users
curl -X POST -H "Content-Type: application/json" -d '{"name":"Ada"}' https://api.example.com/usersCheck if a host is reachable.
ping example.comShow open ports and connections.
ss -tulnPackage management
Install and update packages on Debian/Ubuntu.
sudo apt update
sudo apt install nginx
sudo apt upgradeInstall packages on Fedora/RHEL.
sudo dnf install nginxSSH and remote access
Connect to a remote server.
ssh user@server.com
ssh -i ~/.ssh/key.pem user@server.comCopy files to and from a remote server.
scp file.txt user@server.com:/var/www/
scp user@server.com:/var/log/app.log ./Environment variables
Print an environment variable.
echo $PATHSet a variable for the current session.
export NODE_ENV=productionRun a command with a variable set.
NODE_ENV=production node server.jsShortcuts and tips
Chain commands.
mkdir app && cd app
npm run build || echo "Build failed"Rerun the last command, or rerun it with sudo.
!!
sudo !!Search your command history.
history | grep sshPress Ctrl + R to search history interactively, and Tab to autocomplete paths and commands.
Full-Stack AI Developer Roadmap
From HTML & CSS to working with AI models, all in one structured roadmap.