CodeForFinance
← Back to DevOps & Cloud

Linux Command Line Essentials

The commands you will use every day as a developer. No fluff, just the practical stuff.

Navigation and Search

Everything in Linux is a file, and the command line is how you interact with it. These commands are muscle memory for any developer or DevOps engineer.

# Where am I?
pwd
# /home/user

# List files (long format, human readable, show hidden)
ls -lah

# Change directory
cd /var/log

# Go back to home directory
cd ~

# Go up one level
cd ..

# Create a directory (including parents)
mkdir -p projects/my-app/src

# Find a file by name
find /home -name "*.log" -type f

# Search file contents
grep -r "error" /var/log/ --include="*.log"

File Operations

Copying, moving, deleting, and reading files. The tail -f command is especially useful - it lets you watch a log file update in real time.

# Copy a file
cp config.yaml config.yaml.backup

# Move / rename a file
mv old-name.txt new-name.txt

# Delete a file
rm unwanted-file.txt

# Delete a directory and everything in it
rm -rf old-project/

# View file contents
cat short-file.txt

# View large files page by page
less huge-logfile.log

# View last 50 lines (and follow new lines)
tail -50f /var/log/app.log

# Download a file
curl -O https://example.com/file.tar.gz
wget https://example.com/file.tar.gz

Permissions

Linux permissions control who can read, write, and execute files. Getting these wrong is a common source of "permission denied" errors and security vulnerabilities. Every file has three permission groups: owner, group, and others.

# View permissions
ls -la
# -rw-r--r--  1 user group  1234 Jan 1 12:00 file.txt
# drwxr-xr-x  2 user group  4096 Jan 1 12:00 directory/

# r = read (4), w = write (2), x = execute (1)
# Owner | Group | Others

# Make a script executable
chmod +x deploy.sh

# Set specific permissions (owner: rwx, group: rx, others: r)
chmod 754 script.sh

# Change file owner
chown www-data:www-data /var/www/html -R

Processes

When something is not working, you need to know what is running, what is consuming resources, and how to stop it.

# List running processes
ps aux | grep node

# Real-time process monitor
top
# (or the better alternative)
htop

# Kill a process by PID
kill 12345

# Force kill
kill -9 12345

# Run a process in the background
nohup node server.js &

# Check what is using a port
lsof -i :3000
# or
ss -tlnp | grep 3000

SSH - Remote Access

SSH is how you access remote servers. Always use key-based authentication instead of passwords. It is both more secure and more convenient.

# Connect to a remote server
ssh [email protected]

# Connect with a key file
ssh -i ~/.ssh/my-key.pem [email protected]

# Copy files to a remote server
scp ./deploy.tar.gz user@server:/home/user/

# Copy files from a remote server
scp user@server:/var/log/app.log ./local-copy.log

# Generate an SSH key pair
ssh-keygen -t ed25519 -C "[email protected]"

# Copy your public key to a server
ssh-copy-id user@server

Developer Essentials

As an Amazon Associate we may earn from qualifying purchases.