Essential Command Line Tools for Web Developers
The command line interface (CLI) is an indispensable tool for web developers. This comprehensive guide covers essential commands for daily development tasks, from file management to version control.
File System Navigation and Management
Basic Navigation
bashCopypwd # Print working directory
ls # List directory contents
ls -la # List all files including hidden ones with details
cd directory_name # Change directory
cd .. # Move up one directory
cd ~ # Go to home directory
File Operations
bashCopytouch filename # Create empty file
mkdir directory_name # Create directory
rmdir directory_name # Remove empty directory
rm filename # Remove file
rm -r directory_name # Remove directory and contents
rm -rf directory_name # Force remove directory and contents (use with caution)
cp source destination # Copy file
mv source destination # Move/rename file
File Permissions
bashCopychmod 755 filename # Change file permissions
chown user:group file # Change file ownership
SSH Operations
Connection
bashCopyssh username@hostname # Connect to remote server
ssh -p port username@hostname # Connect using specific port
scp file.txt username@hostname:/path # Copy file to remote server
scp username@hostname:/path file.txt # Copy file from remote server
Key Management
bashCopyssh-keygen -t rsa # Generate SSH key pair
ssh-copy-id username@hostname # Copy SSH key to server
Git Version Control
Repository Operations
bashCopygit init # Initialize repository
git clone repository_url # Clone repository
git remote add origin repository_url # Add remote repository
git remote -v # View remote repositories
Basic Commands
bashCopygit status # Check repository status
git add filename # Stage file
git add . # Stage all changes
git commit -m "message" # Commit changes
git push origin branch_name # Push changes
git pull origin branch_name # Pull changes
Branch Management
bashCopygit branch # List branches
git branch branch_name # Create branch
git checkout branch_name # Switch branch
git checkout -b branch_name # Create and switch branch
git merge branch_name # Merge branch
WordPress CLI
Core Management
bashCopywp core download # Download WordPress
wp core install # Install WordPress
wp core update # Update WordPress
Plugin Management
bashCopywp plugin install plugin_name # Install plugin
wp plugin activate plugin_name # Activate plugin
wp plugin deactivate plugin_name # Deactivate plugin
wp plugin update --all # Update all plugins
Theme Operations
bashCopywp theme install theme_name # Install theme
wp theme activate theme_name # Activate theme
wp theme delete theme_name # Delete theme
Server Management
Process Management
bashCopyps aux # List running processes
top # Monitor system processes
kill process_id # Terminate process
killall process_name # Terminate all processes by name
System Information
bashCopydf -h # Disk usage
free -m # Memory usage
uptime # System uptime
uname -a # System information
File Content Operations
Viewing and Editing
bashCopycat filename # Display file contents
less filename # View file with pagination
head filename # View first 10 lines
tail filename # View last 10 lines
nano filename # Edit file with nano
vim filename # Edit file with vim
Search Operations
bashCopygrep "pattern" filename # Search file for pattern
find . -name "pattern" # Find files by name
locate filename # Locate files (requires updatedb)
Network Operations
Connectivity
bashCopyping hostname # Test network connectivity
traceroute hostname # Trace route to host
netstat -tulpn # List network connections
wget url # Download file from internet
curl url # Transfer data from/to server
Security Best Practices
- Always verify commands before execution, especially with rm -rf
- Use SSH keys instead of passwords when possible
- Keep software and systems updated regularly
- Back up important data before major operations
- Use version control for code changes
- Set appropriate file permissions
- Monitor system logs for suspicious activity
Troubleshooting Tips
- Check command syntax with –help flag
- Verify file paths and permissions
- Monitor system resources during operations
- Keep backup copies of important files
- Use version control to track changes
- Test commands in development environment first
Remember to always exercise caution when using powerful commands, especially those that modify or delete files. Consider creating aliases for frequently used commands to improve efficiency and reduce typing errors.