Linux commands every Drupal developer needs to know.
Keys
Creating keys
ssh-keygen -t rsa
Uploading your public key to server
ssh-copy-id your-ssh-user@server-ip-address
cat ~/.ssh/id_rsa.pub | ssh your-ssh-user@server-ip-address "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Logging into a server
ssh -p port-number your-ssh-user@server-ip-address
Database
Connecting to a database
mysql -h your-host-name -u your-user-name -p
Exporting from a database
mysqldump -h your-host-name -u your-user-name -p your-database-name | gzip -9 > your-export-name.sql.gz
Importing to a database
gunzip
mysql -u your-user-name -p your-database-name
Files & Directories
Taking a backup of the web root directory
tar -cf - /path/to/web/root/directory/ | gzip > backup.tar.gz
Downloading files from another web server
scp -r your-ssh-username@server-ip-address:/path/to/web/root/directory .
Free disk space ?
df -h .
Size of a directory
du -sh
Largest files and directories (under a directory).
du -a /path/to/directory/ | sort -n -r | head -n 10
Searching for files e.g tar.gz (with sizes)
find / -name *.tar.gz -exec du -sh {} \;
List recently modified files
ls -1t | tail -5
Number of lines that match a given search query
grep -r something /path/to/a/directory | grep something-else | wc -l
zgrep something */logs/access*.gz | wc -l
Monitoring
Monitoring log files
tail -f /var/log/syslog /var/log/messages
tail -n 10 /var/log/syslog
Tags: