Essential CentOS Commands for Beginners – A Complete Guide
Introduction
CentOS, a widely used Linux distribution, offers a powerful command-line interface (CLI) for efficient system management. If you’re new to CentOS, learning essential commands can significantly enhance your experience. This guide covers fundamental CentOS commands to help you get started quickly and improve your productivity.
1. System Update and Package Management in CentOS
Keeping your CentOS system updated ensures security and optimal performance.
sudo yum update -y # Refresh package list and update all packages
sudo yum autoremove # Remove unnecessary packages
To install a package on CentOS:
sudo yum install <package_name> -y
To remove a package:
sudo yum remove <package_name> -y
2. File and Directory Management Commands in CentOS
List files and directories:
ls -l # Detailed view
ls -a # Show hidden files
Create and remove directories in CentOS:
mkdir mydir # Create a new directory
rmdir mydir # Remove an empty directory
rm -r mydir # Remove a directory and its contents
Create and delete files in CentOS:
touch myfile.txt # Create an empty file
rm myfile.txt # Delete a file
3. File Operations in CentOS
Copy and move files:
cp file1.txt /path/to/destination # Copy file
mv file1.txt /path/to/destination # Move file (also used for renaming)
View file content:
cat file.txt # Display entire file
less file.txt # View file content page by page
head -n 10 file.txt # Show first 10 lines
4. User and Permission Management in CentOS
Check current user:
whoami
Switch user in CentOS:
su - username
Change file permissions in CentOS:
chmod 755 file.txt # Modify file permissions
chown user:user file.txt # Change file owner
5. Process and System Monitoring Commands in CentOS
Check system resource usage:
top # Real-time system monitoring
htop # Better interactive process viewer (install required: sudo yum install htop -y)
Check disk usage in CentOS:
df -h # Show disk usage
free -m # Show memory usage
Kill a process in CentOS:
kill <PID> # Kill process by ID
killall <process_name> # Kill process by name
6. Networking Commands in CentOS
Check network connectivity:
ping google.com # Test internet connectivity
Display IP address in CentOS:
ip a # Show all network interfaces and IP addresses
Check open ports in CentOS:
netstat -tulnp # Show active listening ports (install required: sudo yum install net-tools -y)
7. System Shutdown and Reboot Commands in CentOS
Shutdown the CentOS system:
sudo shutdown -h now
Reboot the CentOS system:
sudo reboot