❤ Like
🔖 Save
🔗 Share
Eric Hu
Eric Hu

Essential Linux Commands

@thedevspaceio

🐧 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.


CommandDescription
pwdPrint the current working directory.
lsList files and directories.
cdChange directory.
mkdirCreate a directory.
touchCreate an empty file or update its timestamp.
cpCopy files and directories.
mvMove or rename files and directories.
rmDelete files and directories.
catPrint the contents of a file.
lessView a file page by page.
headShow the first lines of a file.
tailShow the last lines of a file, or follow it live.

CommandDescription
grepSearch for text patterns in files.
findFind files and directories by name or attributes.
chmodChange file permissions.
chownChange file ownership.
psList running processes.
killStop a process by ID.
topMonitor processes and resource usage live.
dfShow disk space usage.
duShow the size of files and directories.
curlMake HTTP requests from the terminal.
sshConnect to a remote server.
scpCopy files between machines over SSH.

Navigating the file system

Print the current directory.

bash
pwd

List files and directories.

bash
ls

List files and directories, including hidden files and details.

bash
ls -la

Change directory.

bash
cd /var/www
cd ..        # up one level
cd ~         # home directory
cd -         # previous directory

Working with files and directories

Create directories.

bash
mkdir projects

Create nested directories.

bash
mkdir -p projects/app/src

Create an empty file.

bash
touch index.html

Copy files and directories.

bash
cp file.txt backup.txt
cp -r src/ dist/

Move or rename files.

bash
mv old-name.txt new-name.txt
mv file.txt /var/www/

Delete files and directories.

bash
rm file.txt
rm -r node_modules/

Viewing files

Print an entire file.

bash
cat config.json

View a file page by page. Press q to quit.

bash
less /var/log/syslog

Show the first or last lines of a file.

bash
head -n 20 app.log
tail -n 20 app.log

Follow a log file live.

bash
tail -f /var/log/nginx/access.log

Searching and finding

Search for text inside files.

bash
grep "TODO" app.js

Recusively search for text in a directory.

bash
grep -r "apiKey" src/

Search with case-insensitive matching.

bash
grep -i "error" server.log

Find files by name or type.

bash
find . -name "*.test.js"
find /var/www -type d -name "uploads"

Permissions

Change file ownership.

bash
sudo chown www-data:www-data /var/www/html

Recursively change ownership of a directory.

bash
sudo chown -R $USER:$USER projects/

Change file permissions.

bash
chmod 644 index.html

Each digit represents permissions for Owner, Group, and Others (in that order).

CodeBinarySymbolicPermissions
0000---No permissions
1001--xExecute only
2010-w-Write only
3011-wxWrite + Execute
4100r--Read only
5101r-xRead + Execute
6110rw-Read + Write
7111rwxRead + Write + Execute

Examples:

ValueMeaning
644Owner reads/writes, others read.
755Owner does everything, others read and execute.
600Owner reads/writes only.

You can use symbolic mode to add or remove permissions:

bash
chmod +x deploy.sh
SymbolMeaning
uUser/Owner
gGroup
oOthers
aAll (u+g+o)
+Add permission
-Remove permission
=Set exact permission

Examples:

CommandEffect
chmod u+x fileAdd execute to owner
chmod go-w fileRemove write from group & others
chmod a=r fileSet read-only for all
chmod u=rwx,go=rx fileSet 755 permissions
chmod +x fileAdd execute to all users
chmod -x fileRemove execute from all users

Processes

List running processes.

bash
ps aux

List processes and filter by name.

bash
ps aux | grep node

Monitor processes live. Press q to quit.

bash
top

Stop a process.

bash
kill 1234

Stop a process forcefully.

bash
kill -9 1234

Disk usage

Show disk space on all file systems.

bash
df -h

Show the size of directories.

bash
du -sh node_modules/
du -sh */

Networking

Make an HTTP request.

bash
curl https://api.example.com/users
curl -X POST -H "Content-Type: application/json" -d '{"name":"Ada"}' https://api.example.com/users

Check if a host is reachable.

bash
ping example.com

Show open ports and connections.

bash
ss -tuln

Package management

Install and update packages on Debian/Ubuntu.

bash
sudo apt update
sudo apt install nginx
sudo apt upgrade

Install packages on Fedora/RHEL.

bash
sudo dnf install nginx

SSH and remote access

Connect to a remote server.

bash
ssh user@server.com
ssh -i ~/.ssh/key.pem user@server.com

Copy files to and from a remote server.

bash
scp file.txt user@server.com:/var/www/
scp user@server.com:/var/log/app.log ./

Environment variables

Print an environment variable.

bash
echo $PATH

Set a variable for the current session.

bash
export NODE_ENV=production

Run a command with a variable set.

bash
NODE_ENV=production node server.js

Shortcuts and tips

Chain commands.

bash
mkdir app && cd app
npm run build || echo "Build failed"

Rerun the last command, or rerun it with sudo.

bash
!!
sudo !!

Search your command history.

bash
history | grep ssh

Press 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.

@thedevspaceio
www.thedevspace.io