# Basic Commands for Linux System Administration

***<mark>Basic Commands for Linux System Administration</mark>***

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.

---

## **<mark>1. User and Group Management</mark>**

Managing users and groups is a key part of system administration.

### **Commands**

* `adduser [username]`: Add a new user.
    
    ```plaintext
    sudo adduser john
    ```
    
* `passwd [username]`: Set or update a user password.
    
    ```plaintext
    sudo passwd john
    ```
    
* `usermod -aG [group] [username]`: Add a user to a group.
    
    ```plaintext
    sudo usermod -aG sudo john
    ```
    
* `deluser [username]`: Delete a user.
    
    ```plaintext
    sudo deluser john
    ```
    

---

## **<mark>2. File and Directory Management</mark>**

Knowing how to navigate and manipulate files is crucial.

### **Commands**

* `ls`: List files in a directory.
    
    ```plaintext
    ls -al
    ```
    
* `cd [directory]`: Change the current directory.
    
    ```plaintext
    cd /etc
    ```
    
* `cp [source] [destination]`: Copy files or directories.
    
    ```plaintext
    cp file.txt /home/user/
    ```
    
* `mv [source] [destination]`: Move or rename files.
    
    ```plaintext
    mv file.txt renamed_file.txt
    ```
    
* `rm [file/directory]`: Delete files or directories.
    
    ```plaintext
    rm -rf folder/
    ```
    

---

## **<mark>3. Disk and Filesystem Management</mark>**

Monitoring and managing disk usage ensures optimal performance.

### **Commands**

* `df -h`: Show disk space usage.
    
    ```plaintext
    df -h
    ```
    
* `du -sh [directory]`: Show directory size.
    
    ```plaintext
    du -sh /var/log
    ```
    
* `mount [device] [mountpoint]`: Mount a filesystem.
    
    ```plaintext
    sudo mount /dev/sda1 /mnt
    ```
    
* `umount [mountpoint]`: Unmount a filesystem.
    
    ```plaintext
    sudo umount /mnt
    ```
    
* `lsblk`: List information about block devices.
    
    ```plaintext
    lsblk
    ```
    

---

## **<mark>4. Process and System Monitoring</mark>**

Monitoring system performance is vital for troubleshooting.

### **Commands**

* `top`: Display active processes and resource usage.
    
    ```plaintext
    top
    ```
    
* `ps aux`: View details about running processes.
    
    ```plaintext
    ps aux
    ```
    
* `kill [PID]`: Terminate a process by PID.
    
    ```plaintext
    kill 1234
    ```
    
* `uptime`: Display how long the system has been running.
    
    ```plaintext
    uptime
    ```
    

---

## **<mark>5. Network Management</mark>**

Network troubleshooting is essential for connectivity issues.

### **Commands**

* `ip a`: Display IP address information.
    
    ```plaintext
    ip a
    ```
    
* `ping [hostname/IP]`: Test connectivity.
    
    ```plaintext
    ping google.com
    ```
    
* `netstat -tuln`: Show open ports and services.
    
    ```plaintext
    netstat -tuln
    ```
    
* `ss -tulwn`: Modern alternative to netstat.
    
    ```plaintext
    ss -tulwn
    ```
    
* `scp [source] [user@destination]:[path]`: Copy files securely between systems.
    
    ```plaintext
    scp file.txt user@remote:/home/user/
    ```
    

---

## **<mark>6. Service Management</mark>**

Start, stop, and monitor services on the system.

### **Commands**

* `systemctl start [service]`: Start a service.
    
    ```plaintext
    sudo systemctl start apache2
    ```
    
* `systemctl stop [service]`: Stop a service.
    
    ```plaintext
    sudo systemctl stop apache2
    ```
    
* `systemctl status [service]`: Check the status of a service.
    
    ```plaintext
    sudo systemctl status apache2
    ```
    
* `systemctl enable [service]`: Enable a service to start on boot.
    
    ```plaintext
    sudo systemctl enable apache2
    ```
    
* `systemctl disable [service]`: Disable a service from starting on boot.
    
    ```plaintext
    sudo systemctl disable apache2
    ```
    

---

## **<mark>7. Log Management</mark>**

Logs provide critical insights into system activity.

### **Commands**

* `cat /var/log/[logfile]`: View logs.
    
    ```plaintext
    cat /var/log/syslog
    ```
    
* `tail -f /var/log/[logfile]`: Monitor live logs.
    
    ```plaintext
    tail -f /var/log/syslog
    ```
    
* `journalctl -u [service]`: View logs for a specific service.
    
    ```plaintext
    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.
