Basic Commands for Linux System Administration
Basic Commands for Linux System Administration
Linux is a powerful operating system widely used for servers, system administration, and development. Mastering its commands is essential for every system administrator. Here’s a quick guide to the most fundamental Linux commands for system administration.
1. User and Group Management
Managing users and groups is a key part of system administration.
Commands
adduser [username]: Add a new user.sudo adduser johnpasswd [username]: Set or update a user password.sudo passwd johnusermod -aG [group] [username]: Add a user to a group.sudo usermod -aG sudo johndeluser [username]: Delete a user.sudo deluser john
2. File and Directory Management
Knowing how to navigate and manipulate files is crucial.
Commands
ls: List files in a directory.ls -alcd [directory]: Change the current directory.cd /etccp [source] [destination]: Copy files or directories.cp file.txt /home/user/mv [source] [destination]: Move or rename files.mv file.txt renamed_file.txtrm [file/directory]: Delete files or directories.rm -rf folder/
3. Disk and Filesystem Management
Monitoring and managing disk usage ensures optimal performance.
Commands
df -h: Show disk space usage.df -hdu -sh [directory]: Show directory size.du -sh /var/logmount [device] [mountpoint]: Mount a filesystem.sudo mount /dev/sda1 /mntumount [mountpoint]: Unmount a filesystem.sudo umount /mntlsblk: List information about block devices.lsblk
4. Process and System Monitoring
Monitoring system performance is vital for troubleshooting.
Commands
top: Display active processes and resource usage.topps aux: View details about running processes.ps auxkill [PID]: Terminate a process by PID.kill 1234uptime: Display how long the system has been running.uptime
5. Network Management
Network troubleshooting is essential for connectivity issues.
Commands
ip a: Display IP address information.ip aping [hostname/IP]: Test connectivity.ping google.comnetstat -tuln: Show open ports and services.netstat -tulnss -tulwn: Modern alternative to netstat.ss -tulwnscp [source] [user@destination]:[path]: Copy files securely between systems.scp file.txt user@remote:/home/user/
6. Service Management
Start, stop, and monitor services on the system.
Commands
systemctl start [service]: Start a service.sudo systemctl start apache2systemctl stop [service]: Stop a service.sudo systemctl stop apache2systemctl status [service]: Check the status of a service.sudo systemctl status apache2systemctl enable [service]: Enable a service to start on boot.sudo systemctl enable apache2systemctl disable [service]: Disable a service from starting on boot.sudo systemctl disable apache2
7. Log Management
Logs provide critical insights into system activity.
Commands
cat /var/log/[logfile]: View logs.cat /var/log/syslogtail -f /var/log/[logfile]: Monitor live logs.tail -f /var/log/syslogjournalctl -u [service]: View logs for a specific service.journalctl -u apache2
Conclusion
Mastering these basic Linux commands will build a strong foundation for system administration. Regular practice will enhance your efficiency in managing systems.