Published on November 29, 2024 by tms

Essential Linux Commands Every System Administrator Should Know

Categories: Knowledge hub System Admin Tags:

Linux is a powerful and flexible operating system that has become the backbone of servers, systems, and infrastructure across the globe. For system administrators, mastering Linux commands is a crucial skill that empowers them to manage servers, troubleshoot issues, and ensure seamless system operation. Whether you’re a seasoned Linux professional or just starting your journey, knowing these essential Linux commands is indispensable. In this blog, we’ll cover the must-know commands for system administrators and how they can simplify your day-to-day tasks.


1. Navigating the Filesystem

ls (List Files and Directories)

The ls command lists the contents of a directory. It’s one of the first commands you’ll use to explore files and folders in Linux.

ls
ls -l # Long listing format
ls -a # Include hidden files

cd (Change Directory)

Use cd to navigate between directories.

cd /var/log    # Navigate to /var/log
cd .. # Move one level up
cd ~ # Go to the home directory

pwd (Print Working Directory)

To find out which directory you are currently in, use the pwd command.

pwd

2. File and Directory Management

mkdir (Make Directory)

Create a new directory with mkdir.

mkdir backups

rm (Remove Files or Directories)

Delete files and directories with rm. Use caution with this command!

rm file.txt                  # Remove a file
rm -r directory # Remove a directory and its contents
rm -rf /directory-to-delete # Force remove a directory (use carefully!)

cp (Copy Files or Directories)

Copy files or directories with the cp command.

cp file1.txt file2.txt         # Copy file1.txt to file2.txt
cp -r /source /destination # Copy a directory recursively

mv (Move or Rename Files)

Move or rename files using the mv command.

mv oldname.txt newname.txt     # Rename a file
mv file.txt /destination # Move a file to a directory

3. Viewing and Editing Files

cat (Concatenate and View Files)

Display the contents of a file with cat.

cat file.txt

less (View Large Files)

For large files, use less to view them one page at a time.

less file.txt

nano (Text Editor)

Edit files directly in the terminal using nano.

nano file.txt

4. Managing Users and Permissions

whoami (Current User)

Find out which user you are currently logged in as.

whoami

adduser or useradd (Add User)

Create new users with adduser or useradd.

adduser username   # Add a new user

passwd (Change Password)

Set or change passwords for users.

passwd username

chmod (Change File Permissions)

Modify file permissions using chmod.

chmod 644 file.txt    # Set read/write for owner, read-only for others
chmod +x script.sh # Make a script executable

chown (Change Ownership)

Change the ownership of files and directories.

chown user:group file.txt   # Change owner and group

5. Process Management

ps (Process Status)

View currently running processes.

ps
ps aux # Detailed view of all processes

top or htop (System Monitor)

Monitor system processes and resource usage in real time.

top
htop # (If installed, provides a better interface)

kill (Terminate Processes)

Stop a process using its process ID (PID).

kill 1234   # Terminate process with PID 1234
kill -9 1234 # Force kill a process

6. Network Management

ping (Check Network Connectivity)

Test the connection to another server or device.

ping google.com

ifconfig or ip (Network Configuration)

Display or configure network interfaces.

ifconfig       # Deprecated but still used
ip addr show # New alternative to view IP addresses

netstat or ss (Network Statistics)

View active network connections.

netstat -tuln  # View listening ports
ss -tuln # Faster alternative

7. Disk and Filesystem Management

df (Disk Usage)

View available and used disk space.

df -h  # Display disk usage in a human-readable format

du (Disk Usage per Directory)

Check how much space a directory is using.

du -sh /var/log

mount and umount (Mount/Unmount Filesystems)

Mount and unmount storage devices.

mount /dev/sda1 /mnt
umount /mnt

8. System Updates and Package Management

apt (For Debian-based Systems)

Install, update, and manage software packages on Ubuntu/Debian.

sudo apt update              # Update package list
sudo apt upgrade # Upgrade installed packages
sudo apt install nginx # Install a package
sudo apt remove nginx # Remove a package

yum or dnf (For RHEL-based Systems)

Package management for Red Hat-based distributions.

sudo yum update              # Update packages
sudo yum install httpd # Install a package
sudo yum remove httpd # Remove a package

9. System Monitoring and Troubleshooting

uptime (System Uptime)

Check how long the system has been running.

uptime

free (Memory Usage)

Check memory usage.

free -h  # Display in a human-readable format

dmesg (System Messages)

View kernel messages, useful for troubleshooting hardware issues.

dmesg

journalctl (View System Logs)

Display logs from systemd.

journalctl
journalctl -u sshd # View logs for a specific service

10. Archiving and Compression

tar (Archiving)

Create and extract archives using tar.

tar -cvf archive.tar file1 file2    # Create a tar archive
tar -xvf archive.tar # Extract a tar archive

gzip and gunzip (Compress and Decompress)

Compress files with gzip and decompress with gunzip.

gzip file.txt       # Compress a file
gunzip file.txt.gz # Decompress a file

11. Secure Remote Access

ssh (Secure Shell)

Connect to remote systems securely.

ssh user@remote_server

scp (Secure Copy)

Copy files securely between systems.

scp file.txt user@remote_server:/path/to/destination

rsync (Remote Synchronization)

Synchronize files and directories between systems.

rsync -avz source/ user@remote_server:/destination/

Conclusion

Mastering Linux commands is essential for any system administrator. These commands form the foundation of managing Linux systems efficiently and effectively. Whether you’re troubleshooting, managing users, or configuring networks, these commands will simplify your tasks and make you a more capable administrator. Keep practicing and exploring additional commands to enhance your Linux expertise. Happy learning!


Leave a Reply

Your email address will not be published. Required fields are marked *