Useful Linux commands for web development
In web development, we typically work with a LAMP stack, which means spending a fair amount of time in the terminal. Here I’ve collected the commands I reach for most often.
Problem: You need a quick reference for the most commonly used Linux commands in day-to-day LAMP-based web development — SSH, file transfers, archives, and disk usage.
Solution:
Connect to a remote server via SSH or SFTP
ssh username@hostname -p PORT
sftp username@hostname -oPort=PORT
Copy a folder from localhost to a remote server
scp -r /opt/lampp/htdocs/project/wp-content/uploads username@hostname:/home/username/project/wp-content/
Copy a folder from a remote server to localhost
scp -r username@hostname:/home/username/project/wp-content/uploads/ /opt/lampp/htdocs/project/wp-content/
Copy a single file from a remote server
scp username@hostname:/home/username/project/wp-config.php /opt/lampp/htdocs/project/
Create a zip archive of a directory
zip -r archive.zip directory_name
Extract a zip archive to the current directory
unzip archive.zip
Extract a zip archive to a specific directory
unzip archive.zip -d /tmp/extracted
Check disk usage
df -h # disk space by filesystem
du -sh * # size of each item in the current directory
Find files by name
find /var/www -name "wp-config.php"
NOTE: For large file transfers, rsync is often faster and more reliable than scp because it only transfers changed data: rsync -avz -e 'ssh -p PORT' /local/path/ user@host:/remote/path/. Add --progress to see transfer speed and file count in real time.