Linux Commands

From Dave-Wiki
Revision as of 14:34, 4 February 2025 by Tlyle (talk | contribs) (Created page with "== Linux Administration Guide == This page serves as a comprehensive guide to Linux system administration, including essential commands, system management, and upgrade procedures. == Essential Linux Commands == === File and Directory Management === * <code>ls -l</code> - List files with details * <code>cd /path/to/directory</code> - Change directory * <code>mkdir directory_name</code> - Create a new directory * <code>rm -rf file_or_directory</code> - Remove files/dire...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Linux Administration Guide

This page serves as a comprehensive guide to Linux system administration, including essential commands, system management, and upgrade procedures.

Essential Linux Commands

File and Directory Management

  • ls -l - List files with details
  • cd /path/to/directory - Change directory
  • mkdir directory_name - Create a new directory
  • rm -rf file_or_directory - Remove files/directories
  • cp -r source destination - Copy files and directories
  • mv source destination - Move or rename files

User and Group Management

  • whoami - Show the current user
  • id username - Show user ID and group ID
  • sudo useradd -m username - Add a new user
  • sudo passwd username - Change user password
  • sudo userdel -r username - Delete a user and their home directory
  • sudo groupadd groupname - Create a new group
  • sudo usermod -aG groupname username - Add a user to a group

Process Management

  • ps aux - List all running processes
  • top - Show real-time system processes
  • htop - Interactive process viewer (if installed)
  • kill -9 PID - Forcefully terminate a process
  • pkill process_name - Kill a process by name
  • nohup command & - Run a command in the background

System Monitoring

  • df -h - Show disk usage
  • du -sh /path - Show directory size
  • free -m - Show memory usage
  • uptime - Show system uptime
  • vmstat - Show system performance stats
  • iostat - Show CPU and disk usage

Networking

  • ip a - Show IP addresses
  • ip route - Show routing table
  • ping -c 4 google.com - Send ICMP packets
  • netstat -tulnp - Show active network connections
  • ss -tulnp - Alternative to netstat
  • nslookup domain.com - Query DNS information
  • traceroute google.com - Trace packet route

Package Management

Debian-based (Ubuntu, Debian)

  • sudo apt update - Update package lists
  • sudo apt upgrade - Upgrade installed packages
  • sudo apt install package_name - Install a package
  • sudo apt remove package_name - Remove a package
  • sudo apt autoremove - Remove unused packages

RHEL-based (CentOS, Fedora, RHEL)

  • sudo yum update - Update system packages
  • sudo yum install package_name - Install a package
  • sudo yum remove package_name - Remove a package
  • sudo dnf update - (Fedora) Update packages

File Permissions and Ownership

  • chmod 755 file - Change file permissions
  • chown user:group file - Change file ownership
  • ls -lah - List file permissions
  • umask - Show default permissions

Services and Daemons

  • systemctl start service - Start a service
  • systemctl stop service - Stop a service
  • systemctl restart service - Restart a service
  • systemctl enable service - Enable service at boot
  • systemctl status service - Check service status

Logs and Debugging

  • journalctl -xe - Show system logs
  • tail -f /var/log/syslog - Follow system log
  • grep "error" /var/log/messages - Search logs for errors
  • dmesg | less - Kernel message log

Upgrading Linux

Checking System Version

  • lsb_release -a - Show OS version (Debian/Ubuntu)
  • cat /etc/os-release - Show OS release info
  • uname -r - Show kernel version

Upgrading Ubuntu/Debian

1. Update package lists: sudo apt update 2. Upgrade all installed packages: sudo apt upgrade -y 3. Upgrade distribution: sudo apt dist-upgrade -y 4. Clean up unused packages: sudo apt autoremove -y 5. If upgrading to a new release: sudo do-release-upgrade

Upgrading CentOS/RHEL

1. Update packages: sudo yum update -y 2. Upgrade system: sudo yum upgrade -y 3. If using DNF (Fedora): sudo dnf upgrade --refresh 4. If upgrading to a new version, use: sudo dnf system-upgrade

Kernel Upgrade

  • Check available kernel versions: sudo apt-cache search linux-image
  • Install new kernel: sudo apt install linux-image-version
  • Update GRUB bootloader: sudo update-grub
  • Reboot to apply changes: sudo reboot

Summary

This guide covers essential Linux administration tasks, including user management, networking, services, and system upgrades. For in-depth troubleshooting, refer to system logs and package-specific documentation.