Essential Linux Commands for System Administrators
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Linux is a powerful operating system that is widely used in servers, desktops, and embedded systems. Mastering basic commands is crucial for any system administrator. This guide covers fundamental operations, user management, package management, networking, firewall management, and backup strategies.
1. Basic File and Directory Operations
Create/Change/Remove Directories and Files
Create a Directory:
mkdir directorynameChange Directory:
cd myfolder/Copy a File:
cp filename destinationMove/Rename a File:
mv source destinationRemove a File/Directory:
File:
rm filenameDirectory:
rm -r directoryname/
View and Search File Contents
Display File Content:
cat filenameSearch for Text within a File:
grep pattern filenameView Last 10 Lines of a File:
tail -n 10 filenamePrint Specific Columns:
awk '{ print $1 }' filename
Find and Edit
Find a Directory:
sudo find / -type d -name directorynameFind a File:
sudo find / -type f -name filenameEdit File Text:
sed -i 's/old_text/new_text/g' filename
2. File Permissions and Ownership
File Permissions
Types: Read (r), Write (w), Execute (x)
Modify User Permissions:
sudo chmod u+rwx filenameSet Permissions Numerically:
sudo chmod 777 filename
Ownership Management
Change File Owner/Group:
sudo chown user:group filenameChange File Group:
sudo chgrp group filename
3. User & Group Management
User Management
Create User:
sudo useradd -m -s /bin/bash usernameSet User Password:
sudo passwd usernameDelete a User:
sudo userdel usernameAdd User to Group:
sudo usermod -aG groupname usernameSet Account Expiration:
sudo chage -E YYYY-MM-DD username
Group Management
Create New Group:
sudo groupadd groupnameDelete Group:
sudo groupdel groupname
4. Package Management (Ubuntu/Debian)
Updating and Installing Packages
Update Package List:
sudo apt updateUpgrade All Installed Packages:
sudo apt upgradeInstall Package:
sudo apt install package-nameRemove Package:
sudo apt remove package-namePurge Package:
sudo apt purge package-name
5. Service Management
Service Commands
Check Service Status:
sudo systemctl status servicenameManage Service Lifecycle:
Start:
sudo systemctl start servicenameStop:
sudo systemctl stop servicenameRestart:
sudo systemctl restart servicenameEnable:
sudo systemctl enable servicenameDisable:
sudo systemctl disable servicename
View Service Logs:
sudo journalctl -u servicename
6. Process Management
Process Viewing and Monitoring
List Processes:
ps auxProcess Viewer:
toporhtopI/O Stats:
iostat
Process Killing
Kill Process:
By PID:
kill PIDBy Name:
pkill process_nameForce Kill:
kill -9 PID
7. Networking Management
Network Configuration
View Network Interfaces:
ifconfigorip addrView Routing Table:
ip routePing a Host:
ping hostnameTrace Route to a Host:
traceroute hostname
Network Diagnostics
DNS Lookup:
dig domainornslookup domainList Active Connections:
sudo netstat -tulnorss -tulnScan Open Ports:
sudo nmap -sT IP
8. Firewall Management
UFW (Uncomplicated Firewall)
Manage Firewall:
sudo ufw status,enable,disableAllow Ports:
sudo ufw allow port/protocolDeny Ports:
sudo ufw deny port/protocolAllow Services:
sudo ufw allow http
Firewalld (Alternative)
Check Firewall Status:
sudo firewall-cmd --stateAdd Service to Zone:
sudo firewall-cmd --zone=public --add-service=http --permanentAdd Port to Zone:
sudo firewall-cmd --zone=public --add-port=80 --permanentApply Changes:
sudo firewall-cmd --reload
9. Disk Management
Disk Usage
Check Disk Space:
df -hDisk Usage per Directory:
du -hList Block Devices:
lsblk
Partition and LVM (Logical Volume Management)
Create Partitions:
sudo fdisk /dev/sdXFormat Partition:
sudo mkfs.ext4 /dev/sdX1Mount Partition:
sudo mount /dev/sdX1 /mnt/newdisk
LVM Commands
Create Physical Volume:
sudo pvcreate /dev/sdXCreate Volume Group:
sudo vgcreate volume_group /dev/sdXCreate Logical Volume:
sudo lvcreate -L 10G -n logical_volume volume_groupMount Logical Volume:
sudo mount /dev/volume_group/logical_volume /mnt/my_lvmExtend Volume:
sudo lvextend -L +5G /dev/<volume_group>/<logical_volume>Resize Volume:
sudo resize2fs /dev/<volume_group>/<logical_volume>
10. Backup and Restore with tar and rsync
Backup and Extract with tar
Create Compressed Backup:
tar -cvzf backup.tar.gz /path/to/backupExtract Backup:
tar -xvzf backup.tar.gz -C /path/to/restore
Remote Backup with rsync
Configure SSH:
Generate SSH Key:
ssh-keygenCopy SSH Key to Remote Server:
ssh-copy-id user@remote_ip
Backup with rsync:
rsync -avz source user@remote_ip:/destination