Linux Commands
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 detailscd /path/to/directory
- Change directorymkdir directory_name
- Create a new directoryrm -rf file_or_directory
- Remove files/directoriescp -r source destination
- Copy files and directoriesmv source destination
- Move or rename files
User and Group Management
whoami
- Show the current userid username
- Show user ID and group IDsudo useradd -m username
- Add a new usersudo passwd username
- Change user passwordsudo userdel -r username
- Delete a user and their home directorysudo groupadd groupname
- Create a new groupsudo usermod -aG groupname username
- Add a user to a group
Process Management
ps aux
- List all running processestop
- Show real-time system processeshtop
- Interactive process viewer (if installed)kill -9 PID
- Forcefully terminate a processpkill process_name
- Kill a process by namenohup command &
- Run a command in the background
System Monitoring
df -h
- Show disk usagedu -sh /path
- Show directory sizefree -m
- Show memory usageuptime
- Show system uptimevmstat
- Show system performance statsiostat
- Show CPU and disk usage
Networking
ip a
- Show IP addressesip route
- Show routing tableping -c 4 google.com
- Send ICMP packetsnetstat -tulnp
- Show active network connectionsss -tulnp
- Alternative to netstatnslookup domain.com
- Query DNS informationtraceroute google.com
- Trace packet route
Package Management
Debian-based (Ubuntu, Debian)
sudo apt update
- Update package listssudo apt upgrade
- Upgrade installed packagessudo apt install package_name
- Install a packagesudo apt remove package_name
- Remove a packagesudo apt autoremove
- Remove unused packages
RHEL-based (CentOS, Fedora, RHEL)
sudo yum update
- Update system packagessudo yum install package_name
- Install a packagesudo yum remove package_name
- Remove a packagesudo dnf update
- (Fedora) Update packages
File Permissions and Ownership
chmod 755 file
- Change file permissionschown user:group file
- Change file ownershipls -lah
- List file permissionsumask
- Show default permissions
Services and Daemons
systemctl start service
- Start a servicesystemctl stop service
- Stop a servicesystemctl restart service
- Restart a servicesystemctl enable service
- Enable service at bootsystemctl status service
- Check service status
Logs and Debugging
journalctl -xe
- Show system logstail -f /var/log/syslog
- Follow system loggrep "error" /var/log/messages
- Search logs for errorsdmesg | less
- Kernel message log
Upgrading Linux
Checking System Version
lsb_release -a
- Show OS version (Debian/Ubuntu)cat /etc/os-release
- Show OS release infouname -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.