Linux Command Reference
Searchable Bash Cheat Sheet
Use this terminal-style command guide to quickly find Linux, SSH, networking, package management, deployment, database, and framework commands. All existing command snippets are preserved, and the interface is optimized for faster navigation.
# File & Directory
ls -lah # List files (with size, perms, hidden)
pwd # Show current directory
cd /path/to/dir # Change directory
mkdir project # Make directory
rm -rf folder/ # Remove folder & contents
cp file.txt /dir/ # Copy file
mv old new # Move/Rename file/folder
cat file.txt # Show file content
nano file.txt # Edit file in nano
tail -f log.txt # Live log watching
find . -name "*.php" # Search for files
passwd # change password
# Permissions
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chown user:group file # Change owner
# Process & Services
ps aux | grep php # Show running processes
top / htop # System monitor
kill -9 PID # Kill process
# Users
whoami # Current user
adduser devuser # Add new user
passwd devuser # Set password
# SSH
ssh user@IP # SSH login
ssh-keygen -t ed25519 -C "your_email@example.com" # Create a new SSH key (recommended algorithm)
eval "$(ssh-agent -s)" # Start the SSH authentication agent
ssh-add ~/.ssh/id_ed25519 # Add private key to SSH agent
cat ~/.ssh/id_ed25519.pub # Copy this key and add it to GitHub/GitLab SSH settings
ssh -T git@github.com # Verify SSH authentication with GitHub
git clone git@github.com:username/repository.git # Clone repo without using HTTPS/password
git remote set-url origin git@github.com:username/repository.git # Switch repository from HTTPS to SSH
git remote -v # Confirm SSH remote is set correctly
nano ~/.ssh/config # Create or edit SSH config file Force GitHub to use this SSH key
Host github.com
IdentityFile ~/.ssh/id_ed25519_myname
IdentitiesOnly yes
scp file.zip user@IP:/path # Copy file to server
# Networking
ifconfig / ip a # Show IP addresses
ping google.com # Test connection
curl -I website.com # Check headers
netstat -tulpn # Show open ports
ufw status # Firewall status
ufw allow 22 # Allow SSH
ufw allow 80 # Allow HTTP
ufw allow 443 # Allow HTTPS
# Package Management
sudo apt install package # Install
sudo apt remove package # Remove
dpkg -l | grep php # List installed packages
# Disk & System
df -h # Show disk usage
du -sh folder/ # Folder size
free -m # Show memory usage
uptime # Server uptime/load
reboot # Restart server
shutdown -h now # Shutdown server
# Archives
tar -czvf backup.tar.gz folder/ # Create tar.gz
tar -xzvf backup.tar.gz # Extract tar.gz
unzip file.zip # Extract zip
zip -r backup.zip folder/ # Create zip
# Git & Deployment
sudo git clone repo.git
sudo git pull
sudo git push
sudo git merge branch_name
sudo git checkout -b new-feature
# Install PHP APACHE MYSQL
sudo apt update && sudo apt upgrade -y # Update system
sudo apt-get update # apt-get Older, low-level tool (stable since the 2000s).
sudo apt update # apt Newer, user-friendly frontend (introduced in Ubuntu 16.04+).
sudo apt install apache2 # Install APACHE2 Apache config /etc/apache2/apache2.conf
sudo apt install mysql-server # Install MYSQL
sudo apt install curl # Install CURL
sudo apt install php -y # Install PHP
sudo apt install -y php-bcmath php-bz2 php-intl php-gd php-mbstring php-mcrypt php-mysql php-zip libapache2-mod-php
# Install REDIS
sudo apt update && sudo apt upgrade -y # Update system packages
sudo apt-get install -y lsb-release curl gpg # Install required dependencies
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg # Download and add Redis GPG key
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg # Set correct permissions for keyring
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list # Add Redis APT repository
sudo apt-get update # Refresh package list after adding Redis repo
sudo apt-get install -y redis # Install Redis server
sudo systemctl status redis-server # Check Redis service status
# Check firewall application profiles
sudo ufw app list
# Allow Apache traffic
sudo ufw allow 'Apache Full' # Apache Full → allows both port 80 (HTTP) and port 443 (HTTPS)
sudo ufw allow 'Apache' # Apache → only allows port 80 (HTTP)
sudo ufw allow 'Apache Secure' # Apache Secure → only allows port 443 (HTTPS)
# Install Composer
sudo apt install php-cli unzip curl -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# In Folder
composer install # Composer reads composer.json and downloads all required PHP packages into the vendor/ folder.
# Install Node Version Manager (NVM):
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
# Install Node
sudo apt install nodejs
nvm install 20
nvm use 20
# Alternative Node.js install
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs
# Force install ignoring engine checks
npm install --ignore-engines
# Reinstall dependencies:
rm -rf node_modules package-lock.json
npm install
# VERSIONS
php -v
node -v
npm -v
composer -v
# Start And enable installed services
sudo systemctl start / enable / restart status apache2.service
sudo systemctl start / enable / restart status mysql.service
sudo /etc/init.d/apache2 restart
# Install phpMyAdmin
sudo apt-get install phpmyadmin php-mbstring php-gettext
# Enable necessary PHP extensions
sudo phpenmod mcrypt
sudo phpenmod mbstring
# Edit Apache virtual host config
sudo nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias www.mywebsite.com
DocumentRoot /var/www/html/project
<Directory /var/www/html/project>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/project_error.log
CustomLog ${APACHE_LOG_DIR}/project_access.log combined
</VirtualHost>
# Create an
sudo mkdir -p /var/www/mywebsite
sudo chown -R $USER:$USER /var/www/mywebsite
# Edit Config
sudo nano /etc/apache2/sites-available/project.conf
# ENABLE site
sudo a2ensite project.conf
sudo systemctl reload apache2
# Disable Site
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
# Test Apache config:
sudo apache2ctl configtest
# reload apache2
# SSH
ssh keygen # generate key in you own system for practice
# Go to pem file directory
sudo chmod 400 file.pem
sudo ssh -i file.pem ubuntu@0.0.0.0
# Addition ---------------------------------
# SSL / HTTPS (Let's Encrypt)
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
sudo certbot renew --dry-run # Test auto-renewal
# CRON JOBS (Scheduled Tasks)
crontab -e
# Example entries:
* * * * * php /var/www/project/artisan schedule:run >> /dev/null 2>&1 # Laravel scheduler
0 2 * * * mysqldump -u root -p dbname > /home/backup/dbname_$(date +\%F).sql
# Daily DB backup
0 3 * * 0 rsync -a /var/www/project/ /home/backup/project/ # Weekly project backup
# SUPERVISOR (Keep Laravel Queue Running)
sudo apt install supervisor -y
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
# Example supervisor config:
# [program:laravel-worker]
# process_name=%(program_name)s_%(process_num)02d
# command=php /var/www/project/artisan queue:work --sleep=3 --tries=3 --max-time=3600
# autostart=true
# autorestart=true
# stopasgroup=true
# killasgroup=true
# user=www-data
# numprocs=1
# redirect_stderr=true
# stdout_logfile=/var/www/project/storage/logs/worker.log
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
# LOGS & MONITORING
journalctl -u apache2 -f # Apache live logs
journalctl -u mysql -f # MySQL logs
tail -f /var/www/project/storage/logs/laravel.log # Laravel logs
df -h # Disk usage
htop # Process monitor
# BACKUPS (Manual + Cron)
# MySQL backup
mysqldump -u root -p dbname > /home/backup/dbname_$(date +%F).sql
# All databases
mysqldump -u root -p --all-databases > /home/backup/all_$(date +%F).sql
# Rsync project files
rsync -avz /var/www/project/ /home/backup/project_$(date +%F)/
# Add cron for automatic backups
crontab -e
# 0 1 * * * mysqldump -u root -p'password' dbname > /home/backup/dbname_$(date +\%F).sql
# 0 2 * * * rsync -avz /var/www/project/ /home/backup/project_$(date +\%F)/
# Node
# NPM BASICS
npm -v # Check npm version
npm init -y # Create package.json (default)
npm init # Create package.json (interactive)
# INSTALL PACKAGES
npm install -- pkg -- # Install locally (default)
npm install -- pkg --@1.2.3 # Install specific version
npm install -g -- pkg -- # Install globally
npm install # Install deps from package.json
npm ci # Clean install (faster, from package-lock.json)
# REMOVE / UPDATE
npm uninstall -- pkg -- # Remove package
npm update -- pkg -- # Update package
npm update # Update all packages
npm outdated # Check outdated packages
# RUNNING SCRIPTS
npm run -- script -- # Run script from package.json
npm run build # Common script
npm run dev # Common script
npm test # Run "test" script
npm start # Run "start" script
# PACKAGE INFO
npm list # List local deps
npm list -g --depth=0 # List global deps
npm view -- pkg -- # Info about a package
npm view -- pkg -- versions # List all versions
npm search -- pkg -- # Search npm registry
# NPX (Run without install)
npx -- pkg -- # Run a package directly
npx create-react-app myapp
npx laravel-vite-plugin
# CACHE & CONFIG
npm cache clean --force # Clear npm cache
npm config list # Show npm configs
npm config set registry https://registry.npmjs.org/
# PACKAGE LOCK & AUDIT
npm audit # Scan for vulnerabilities
npm audit fix # Auto-fix issues
npm shrinkwrap # Lock exact versions (like package-lock.json)
# PUBLISH (if making packages)
npm login # Login to npm
npm publish # Publish package
npm version patch # Bump version (patch)
npm version minor # Bump version (minor)
npm version major # Bump version (major)
# Install PM2
npm install -g pm2 # Install PM2 globally
pm2 --version # Check PM2 version
# Start Applications
pm2 start app.js # Start a Node.js app
pm2 start app.js --name api # Start app with custom name
pm2 start npm --name frontend -- run start # Start npm script using PM2
pm2 start ecosystem.config.js # Start apps using ecosystem file
# Process Management
pm2 list # List all running processes
pm2 show api # Show detailed info of a process
pm2 restart api # Restart a specific app
pm2 restart all # Restart all apps
pm2 stop api # Stop a specific app
pm2 stop all # Stop all apps
pm2 delete api # Remove app from PM2
pm2 delete all # Remove all apps from PM2
# Logs & Monitoring
pm2 logs # Show logs of all apps
pm2 logs api # Show logs for a specific app
pm2 monit # Real-time CPU & memory monitoring
# Startup & Auto-Restart (Production)
pm2 startup # Generate startup script for boot
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u $USER --hp $HOME # Fix startup path issues (recommended)
pm2 save # Save current process list for reboot restore
pm2 resurrect # Restore apps after reboot
# Reload & Zero-Downtime
pm2 reload api # Zero-downtime reload (cluster mode)
pm2 reload all # Reload all apps
# Ecosystem File
pm2 init # Create ecosystem.config.js
pm2 start ecosystem.config.js --env production # Start apps in production mode
# Useful Maintenance Commands
pm2 flush # Clear all logs
pm2 reloadLogs # Reload log files without downtime
pm2 kill # Stop PM2 daemon completely
pm2 update # Update PM2 in-memory processes
# Login to MySQL
mysql -u root -p
# Reset Password
# 1 Stop Mysql
sudo systemctl stop mysql
# 2 Start MySQL without authentication
sudo mysqld_safe --skip-grant-tables & # Grant Access Tologin without
# if error mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
# Create the directory manually
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
# then Try again from 1
# 3 login
mysql -u root
# Inside MySQL prompt, run
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword';
# If ALTER USER gives an error, try:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('YourNewPassword');
EXIT; # Exit MySQL:
# Mysql Server
sudo systemctl stop mysql # Stop Mysql Server
sudo systemctl start mysql # Start Mysql Server
# Mysql Database
CREATE DATABASE database_name # Create Database
SHOW TABLES; # All tables
SHOW DATABASES; # All database
USE database_name # Go in database
# CREATE TABLE, SELECT, INSERT, UPDATE, DELETE
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
SELECT * FROM users;
INSERT INTO users (name, email) VALUES ('name', 'email');
UPDATE users SET name = 'name', email = 'email'
DELETE FROM users WHERE id = 1
EXIT;
# Import Database -- Restore from Backup
# Import .sql file
mysql -u username -p database_name /path/to/file.sql
# Import from a .zip file
unzip -p /var/www/backup.zip | mysql -u username -p database_name # one step
unzip backup.zip
mysql -u username -p database_name backup.sql
# Export from database
mysqldump -u root -p --all-databases > all-databases.sql # all database
mysqldump -u root -p database_name > /home/myuser/database-dump.sql # database
mysqldump -u root -p database_name table_name > users-table.sql # table
mysqldump -u root -p --no-data database_name > schema.sql # only schema
# LARAVEL
# Install Laravel globally
composer global require laravel/installer
# Add composer global bin path to system PATH
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Verify installation
laravel --version
# Create a project
laravel new blog
# Move inside project
cd blog
php artisan serve
# Create Laravel project without installing Laravel
composer create-project laravel/laravel blog2
# Move inside project
cd blog2
php artisan serve
# Commands
# Show all commands
php artisan list
# Help for specific command
php artisan help serve
# App Key
php artisan key:generate
# Cache / Config / Route
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan optimize
# Migrate
php artisan migrate
php artisan migrate:rollback # Undo last batch
php artisan migrate:reset # Undo all
php artisan migrate:fresh # Drop all tables & re-run all migrations
php artisan migrate:status # Show migration status
# Seed database
php artisan db:seed
php artisan db:seed --class=UserSeeder
# Make Migration
php artisan make:migration create_users_table
php artisan make:migration add_status_to_orders_table --table=orders
# Make model
php artisan make:model modal_name
php artisan make:model modal_name -m # with migration
php artisan make:model modal_name -mc # with migration + controller
# Make Controller
php artisan make:controller NameController
php artisan make:controller NameController --resource
php artisan make:controller Api/NameController --api
# Middleware
php artisan make:middleware CheckUser
php artisan make:request StoreUserRequest
php artisan make:job ProcessOrder
php artisan make:event OrderCreated
php artisan make:listener SendEmailNotification
php artisan make:seeder UserSeeder
php artisan make:factory UserFactory
# Routing Debuging
php artisan route:list # Show all routes
php artisan route:list --name=api
php artisan tinker # Interactive shell for Laravel
php artisan db:show # Show DB info (Laravel 10+)
# Queue Jobs
php artisan queue:work
php artisan queue:listen
php artisan queue:restart
# Testing
php artisan test
php artisan test --filter UserTest
# More
composer update # Update dependencies
composer install # Install dependencies
php artisan storage:link # Link storage to public
php artisan down # Maintenance mode
php artisan up # Disable maintenance mode