Skip to content

Latest commit

 

History

History
219 lines (193 loc) · 3.13 KB

CLI_CHEATSHEET.md

File metadata and controls

219 lines (193 loc) · 3.13 KB

Inside Server

System Information:

  • View system info:
    uname -a
  • Check memory usage:
    free -h
  • Check disk usage:
    df -h
  • Check CPU usage:
    top
    or
    htop
  • Check system uptime:
    uptime

User and Permissions:

  • List all users:
    cut -d: -f1 /etc/passwd
  • Switch user:
    su - username
  • Change user password:
    sudo passwd username
  • Add a user:
    sudo adduser username

File Operations:

  • List files in directory:
    ls -l
  • Change directory:
    cd /path/to/directory
  • Copy files:
    cp source destination
  • Move/rename files:
    mv source destination
  • Remove files:
    rm filename
  • Edit a file (with nano editor):
    nano filename

Networking:

  • Check IP address:
    ip a
  • Check open ports:
    sudo netstat -tuln
  • Test connectivity to a host:
    ping hostname_or_ip
  • Check active network connections:
    ss -tuln

Package Management (Debian-based systems):

  • Update packages:
    sudo apt update
  • Upgrade packages:
    sudo apt upgrade
  • Install a package:
    sudo apt install package_name
  • Remove a package:
    sudo apt remove package_name

Services Management:

  • Check service status:
    sudo systemctl status service_name
  • Start a service:
    sudo systemctl start service_name
  • Stop a service:
    sudo systemctl stop service_name
  • Enable a service to start at boot:
    sudo systemctl enable service_name
  • Restart a service:
    sudo systemctl restart service_name

Logs:

  • View system logs (most recent logs):
    sudo journalctl -xe
  • View specific service logs:
    sudo journalctl -u service_name

Firewall (UFW):

  • Check UFW status:
    sudo ufw status
  • Allow port (e.g., port 80 for HTTP):
    sudo ufw allow 80/tcp
  • Enable UFW:
    sudo ufw enable
  • Disable UFW:
    sudo ufw disable
  • Check firewall rules:
    sudo ufw status verbose

Processes:

  • Show running processes:

    ps aux
  • Kill a process:

    kill process_id
  • Kill a process by name:

    pkill process_name

SSH:

  • SSH into server:
    ssh username@hostname_or_ip
  • SSH with a specific port:
    ssh -p port_number username@hostname_or_ip

Disk Usage & Cleanup:

  • Check disk usage:
    sudo du -sh /path/to/folder
  • Clean up apt cache:
    sudo apt clean

Backup and Restore:

  • Create a tar backup:
    tar -czvf backup.tar.gz /path/to/directory
  • Extract a tar backup:
    tar -xzvf backup.tar.gz