Linux Commands For Admins
System & Process Management
top
– Monitor processes
Example:top
View CPU and memory usage in real-time.htop
– Enhanced process monitor
Example:htop
(If not installed:sudo dnf install htop
)
Use arrow keys to navigate processes interactively.ps aux
– Show all running processes
Example:ps aux | grep firefox
Check if Firefox is running.systemctl status
– Check service status
Example:systemctl status sshd
See if the SSH service is active.journalctl -xe
– View logs
Example:journalctl -xe
View system error logs when debugging failures.uptime
– How long the system has been up
Example:uptime
Useful for checking server availability.free -h
– View memory usage
Example:free -h
Helps when diagnosing performance issues.df -h
– Check disk space
Example:df -h /home
Check available space on/home
.du -sh *
– Show size of folders
Example:du -sh /var/log/*
Find which log folder is taking the most space.
Package Management (DNF)
sudo dnf update
– Update package info
Example:sudo dnf update
Update the local package database.sudo dnf upgrade
– Upgrade all packages
Example:sudo dnf upgrade
Install the latest software and security updates.sudo dnf install <package>
– Install packages
Example:sudo dnf install git
Install Git on your system.sudo dnf remove <package>
– Uninstall packages
Example:sudo dnf remove gedit
Remove the Gedit text editor.dnf list installed
– List all installed packages
Example:dnf list installed | grep nginx
Check ifnginx
is installed.dnf search <term>
– Search for packages
Example:dnf search vscode
Look for available Visual Studio Code packages.
Networking
ip a
– Show network interfaces
Example:ip a
Get your IP address and network interface info.ping <host>
– Check connectivity
Example:ping google.com
Verify internet connection.curl <url>
– Download web data
Example:curl https://api.ipify.org
Display your public IP address.ss -tuln
– View open ports
Example:ss -tuln
Check which services are listening for connections.nmcli
– Manage network connections
Example:nmcli device status
List all network devices and their states.
File & Directory Operations
ls -lah
– List detailed files
Example:ls -lah /var/log
View size, ownership, and permissions of logs.cp -r <src> <dst>
– Copy files/directories
Example:cp -r ~/projects /mnt/backup/
Backup a project directory.mv <src> <dst>
– Move or rename
Example:mv report.txt old_report.txt
Rename a file.rm -rf <dir>
– Delete files/directories
Example:rm -rf /tmp/test-folder
Delete a test folder (use cautiously!).find . -name "<pattern>"
– Search for files
Example:find . -name "*.log"
Find all log files in the current directory tree.
User & Permission Management
sudo adduser <username>
– Add a user
Example:sudo adduser john
Create a user named John.sudo passwd <username>
– Set password
Example:sudo passwd john
Set or reset John's password.sudo usermod -aG wheel <username>
– Add to sudo group
Example:sudo usermod -aG wheel john
Give John sudo privileges.chmod +x <file>
– Make script executable
Example:chmod +x deploy.sh
Allow a script to be run as a program.chown <user>:<group> <file>
– Change ownership
Example:chown john:john report.txt
Give John ownership of a file.
Bonus: Miscellaneous Essentials
whoami
– Show current username
Example:whoami
Confirm which user you’re logged in as.hostnamectl
– Set or check hostname
Example:hostnamectl set-hostname dev-server
Rename your system.grep <pattern> <file>
– Search text
Example:grep "error" /var/log/messages
Find error messages in log files.tar -czvf archive.tar.gz <dir>
– Compress files
Example:tar -czvf backup.tar.gz ~/projects
Archive and compress a folder.crontab -e
– Edit scheduled tasks
Example:crontab -e
Schedule a backup script to run every night.alias ll='ls -l'
– Create command shortcuts
Example:alias gs='git status'
Speed up frequent tasks with aliases.echo $PATH
– Show environment path
Example:echo $PATH
See where the shell looks for executables.which <command>
– Locate binaries
Example:which python
Find the path to the installed Python binary.man <command>
– View manual
Example:man chmod
Get help for any command.
Examples
System & Process Management
-
top
top # Monitor CPU and memory usage in real-time, useful to find resource hogs.
-
htop
htop # Navigate interactively to find processes and kill if needed (press F9).
-
ps aux
ps aux | grep firefox # Check if Firefox browser is currently running.
-
systemctl status
systemctl status sshd # Verify if the SSH service is active and running.
-
journalctl -xe
journalctl -xe # View recent system errors for troubleshooting failed services.
-
uptime
uptime # Check how long the server has been running and its load averages.
-
free -h
free -h # Diagnose memory usage including swap in a human-readable format.
-
df -h
df -h /home # Check free disk space on the /home partition.
-
**du -sh ***
du -sh /var/log/* # Find which log directories consume the most space.
Package Management (DNF)
-
sudo dnf update
sudo dnf update # Refresh package metadata before installing or upgrading.
-
sudo dnf upgrade
sudo dnf upgrade # Upgrade all packages to latest versions including security fixes.
-
sudo dnf install
sudo dnf install git # Install Git version control system on your machine.
-
sudo dnf remove
sudo dnf remove gedit # Remove Gedit text editor if no longer needed.
-
dnf list installed
dnf list installed | grep nginx # Check if nginx web server is installed.
-
dnf search
dnf search vscode # Search for Visual Studio Code or related packages.
Networking
-
ip a
ip a # Show all network interfaces and their IP addresses.
-
ping
ping google.com # Test if your system has internet connectivity.
-
curl
curl https://api.ipify.org # Retrieve and display your public IP address.
-
ss -tuln
ss -tuln # List all listening TCP/UDP ports and associated services.
-
nmcli
nmcli device status # Show network device status and connections.
File & Directory Operations
-
ls -lah
ls -lah /var/log # View detailed list of log files with sizes and permissions.
-
cp -r
cp -r ~/projects /mnt/backup/ # Copy project directory to backup location.
-
mv
mv report.txt old_report.txt # Rename a report file.
-
rm -rf
rm -rf /tmp/test-folder # Force delete a temporary folder (be careful!).
-
find . -name ""
find . -name "*.log" # Find all log files recursively in current directory.
User & Permission Management
-
sudo adduser
sudo adduser john # Create a new user named John.
-
sudo passwd
sudo passwd john # Set or reset John's user password.
-
sudo usermod -aG wheel
sudo usermod -aG wheel john # Add John to sudoers group for admin privileges.
-
chmod +x
chmod +x deploy.sh # Make a deployment script executable.
-
chown :
chown john:john report.txt # Change ownership of a report file to user John.
Bonus: Miscellaneous Essentials
-
whoami
whoami # Confirm your current logged-in user.
-
hostnamectl
hostnamectl set-hostname dev-server # Rename your machine to 'dev-server'.
-
grep
grep "error" /var/log/messages # Search for "error" keywords in system messages.
-
tar -czvf archive.tar.gz
tar -czvf backup.tar.gz ~/projects # Archive and compress your projects folder.
-
crontab -e
crontab -e # Edit cron jobs to schedule regular backups.
-
alias
alias gs='git status' # Create shortcut for a common Git command.
-
echo $PATH
echo $PATH # Show directories where executables are searched.
-
which
which python # Find full path of installed Python interpreter.
-
man
man chmod # Open manual page for chmod command.
Comments
Post a Comment