Subscribe - Thapa Technical

Linux Commands Every VPS User Must Know!

Essential Linux Commands for Developers

🟢 System Updates and Package Management with APT

✅ What is APT? APT (Advanced Package Tool) is a package management system used on Debian-based Linux distributions (like Ubuntu). It helps you manage software packages—installing, updating, and removing them.

1. Updating Package Repositories
sudo apt update
Definition: Refreshes package lists from repositories. Essential before installing software.
2. Upgrading Installed Packages
sudo apt upgrade -y
Definition: Installs new versions of packages. The -y flag auto-confirms.
3. Installing Packages (MySQL/MongoDB Example)
sudo apt install mysql-server -y
sudo apt install mongodb -y
Definition: Installs packages with -y for automatic confirmation.
4. Removing Packages
sudo apt remove mysql-server -y
Definition: Uninstalls packages but keeps config files.

🟢 SYSTEMCTL - System & Service Manager

✅ What is Systemctl? Controls system services on Linux (start, stop, restart, enable, disable, status).

1. Starting a Service
sudo systemctl start mysql
Definition: Starts the service.
2. Stopping a Service
sudo systemctl stop mysql
Definition: Stops the service.
3. Enabling/Disabling a Service on Boot
sudo systemctl enable mysql
sudo systemctl disable mysql
Definition: Controls service startup behavior.
4. Checking Service Status
sudo systemctl status mysql
Definition: Shows current status of the service.

🟢 Handling Files in Linux

✅ Why Manage Files from the Command Line? Managing files from the command line on a VPS is efficient, especially when working remotely. It's faster and often necessary for server management.

ℹ️ Navigating and Viewing Files
# Navigate directories
cd /path/to/directory

# List files
ls -la
1. Creating and Deleting Files
# Create a file
touch myfile.txt

# Delete a file
rm myfile.txt
Definition:
  • touch creates an empty file if it doesn't exist.
  • rm removes a file permanently.
Example: Create a placeholder or remove unwanted files.
2. Reading and Writing to a File
# Read a file
cat myfile.txt

# Write to a file
echo "Hello, World!" > myfile.txt
Definition:
  • echo prints text and can redirect output to files.
  • Use > to overwrite or >> to append.
Example: Store output or create a quick text file.
3. Editing a File
sudo nano myfile.txt
Definition:
  • nano opens a simple terminal-based text editor.
  • vi or vim are alternatives with more features but a steeper learning curve.
Example: Edit Nginx config to set up reverse proxy.
4. Reading Files with Less and More
less myfile.txt
Definition:
  • less displays content page by page, allowing navigation.
  • more does similar but without backward scrolling.
Example: View large log files easily.

🟢 Node.js and NPM

# Check Node.js version
node -v

# Check NPM version
npm -v

# Install dependencies for project
cd /path/to/project && npm install

# Run Node.js application
npm start

# Install PM2 for process management
npm install -g pm2

# Start application with PM2
pm2 start app.js --name "mern-app"

# List running PM2 applications
pm2 list

# Configure PM2 to start on boot
pm2 startup

Node.js commands for version checking, package management, and running applications with process management using PM2.

🟢 Network Management

🔥 Firewall with UFW
# Install UFW
apt install ufw

# Allow specific ports
ufw allow 22    # SSH
ufw allow 80    # HTTP
ufw allow 443   # HTTPS
ufw allow 3000  # Node.js app

# Enable firewall
ufw enable

# Check status
ufw status

Uncomplicated Firewall (UFW) provides an easy way to manage your server's firewall rules to protect your server while allowing legitimate traffic through.

🟢 Monitoring and Troubleshooting

📊 System Resources
# Check disk space
df -h

# Check memory usage
free -m

# Check system load
top

# or more user-friendly alternative
htop

Essential commands for monitoring system resources including disk space, memory usage, and CPU load to maintain optimal server performance.

Pro Tip: Always check system resources before troubleshooting performance issues. Many problems stem from disk space, memory, or CPU constraints.

© 2025 THAPA TECHNICAL. All rights reserved.

Created for developers who want to master the Linux command line.