# 12 Must-Know Linux command for DevOps Beginners to Boost Efficiency (With Examples)

*Linux is a powerful tool used by DevOps engineers to manage servers, fix problems, and automate tasks. Learning a few key commands can make your work easier and faster. This article explains* ***12 simple Linux commands*** *with real-life examples that beginners can understand and use.*

---

## 1\. `grep` – Find Words in Files

**What It Does:** Searches for specific words in files, like finding "error" in a log file.  
**Example:** Your website has errors, and you want to check the server logs.  
**Command:**

```bash
grep -i "error" /var/log/nginx/error.log
```

* `-i`: Ignores if the word is in uppercase or lowercase (finds "Error" or "ERROR").  
    **Try This:**
    
* Look for "404" errors:
    
    ```bash
    grep "404" /var/log/nginx/access.log
    ```
    

---

## 2\. `chmod` & `chown` – Control File Access

**What They Do:** `chmod` changes who can use a file; `chown` changes who owns it.  
**Example:** Your script [`deploy.sh`](http://deploy.sh) isn’t working because it lacks permission.  
**Commands:**

```bash
chmod +x deploy.sh        # Makes the script runnable
chown root:root deploy.sh # Sets the owner to "root"
```

**Why It’s Useful:**

* Secure files like SSH keys: `chmod 600 ~/.ssh/id_rsa` stops others from reading them.
    

---

## 3\. `curl` – Test Websites and APIs

**What It Does:** Checks if a website or API is working by sending requests.  
**Example:** Your app’s payment system is slow. Test if it responds.  
**Command:**

```bash
curl -X GET https://api.yoursite.com/payments -H "Authorization: Bearer YOUR_TOKEN"
```

**Fun Tip:**

* Check how fast a website loads:
    
    ```bash
    curl -o /dev/null -s -w '%{time_total}s\n' https://google.com
    ```
    

---

## 4\. `rsync` – Copy Files Safely

**What It Does:** Copies files between computers or servers while keeping them safe.  
**Example:** Back up your website files to another server.  
**Command:**

```bash
rsync -avz /var/www/html/ user@backup-server:/backup/
```

* `-a`: Keeps file details like permissions.
    
* `-v`: Shows what’s copying.
    
* `-z`: Makes the transfer faster by compressing files.
    

---

## 5\. `systemctl` – Manage Services

**What It Does:** Starts, stops, or checks services like web servers.  
**Example:** Your Nginx web server stops working. Restart it.  
**Commands:**

```bash
sudo systemctl restart nginx   # Restarts Nginx
sudo systemctl status nginx   # Checks if it’s running
```

**Good to Know:**

* Make Nginx start automatically: `sudo systemctl enable nginx`.
    

---

## 6\. `awk` – Pull Out Data

**What It Does:** Extracts specific information from a list, like usernames or CPU usage.  
**Example:** Find which user is using too much CPU.  
**Command:**

```bash
ps aux | awk '{print $1, $3}' | sort -k2 -nr | head -n 5
```

**What It Means:**

* `ps aux`: Shows all running programs.
    
* `awk`: Picks username and CPU usage.
    
* `sort` and `head`: Lists the top 5 users using the most CPU.
    

---

## 7\. `cron` – Schedule Tasks

**What It Does:** Runs tasks automatically at set times, like cleaning old files.  
**Example:** Delete old logs every Sunday at midnight.  
**Commands:**

```bash
# Open the cron editor
crontab -e

# Add this line
0 0 * * 0 /usr/bin/find /var/log -name "*.log" -mtime +7 -delete
```

**What It Does:**

* Runs every Sunday (`0 0 * * 0`) to delete logs older than 7 days.
    

---

## 8\. `lsof` – Check Open Ports

**What It Does:** Shows which program is using a specific port.  
**Example:** Port 8080 is blocked, and you need to find out why.  
**Command:**

```bash
sudo lsof -i :8080
```

**Example Output:**

```plaintext
COMMAND  PID USER   FD TYPE DEVICE SIZE/OFF NODE NAME
node    1234 root   21u IPv4 23456      0t0  TCP *:8080 (LISTEN)
```

**What It Means:** A Node.js program (PID 1234) is using port 8080.

---

## 9\. `journalctl` – Read System Logs

**What It Does:** Shows logs to help you understand why something went wrong.  
**Example:** Your server restarted suddenly. Find out why.  
**Command:**

```bash
journalctl -u systemd-logind --since "10 minutes ago"
```

* `-u`: Looks at logs for a specific service.
    
* **Another Use:** Check kernel logs with `journalctl -k`.
    

---

## 10\. `tar` – Pack and Unpack Files

**What It Does:** Combines files into one archive or extracts them.  
**Example:** Send a project folder to another server.  
**Commands:**

```bash
tar -czvf app.tar.gz /home/project    # Packs the folder
tar -xzvf app.tar.gz -C /var/www      # Unpacks it
```

* `-c`: Creates an archive.
    
* `-x`: Extracts files.
    
* `-z`: Compresses to save space.
    
* `-v`: Shows what’s happening.
    

11. ## `find` – Search for Files
    

**What It Does:** Searches for files or folders based on name, size, or other criteria.  
**Example:** You need to find all log files in the `/var/log` folder.  
**Command:**

```bash
find /var/log -name "*.log"
```

**What It Means:**

* `/var/log`: Where to search.
    
* `-name "*.log"`: Looks for files ending in `.log`.  
    **Another Example:** Find files larger than 100MB:
    

```bash
find / -type f -size +100M
```

* `-type f`: Only finds files (not folders).
    
* `-size +100M`: Files bigger than 100MB.  
    **Why It’s Useful:** Helps locate specific files to clean up space or troubleshoot issues.
    

12. ## `du` – Check Disk Space Usage
    
    **What It Does:** Shows how much space files or folders are using.  
    **Example:** You want to see how much space the `/var/log` folder is taking.  
    **Command:**
    
    ```bash
    du -sh /var/log
    ```
    
    **Explanation:**
    
    * `-s`: Summarizes the total size.
        
    * `-h`: Shows the size in a readable format (e.g., MB or GB).  
        **Another Example:** Check the size of all folders in `/home`:
        
    
    ```bash
    du -h /home | sort -h
    ```
    
    * `sort -h`: Lists folders from smallest to largest size.  
        **Why It Helps:** Helps you find which files or folders are using too much disk space.
        
    

---

## Bonus: Handy Command Combos

1. **Find High CPU Usage:**
    
    ```bash
    top -c   # Find the program’s PID
    strace -p <PID>   # See what it’s doing
    ```
    
2. **Find Big Files:**
    
    ```bash
    find / -type f -size +100M -exec ls -lh {} \;
    ```
    
3. **Check Disk Space Every 5 Seconds:**
    
    ```bash
    watch -n 5 df -h
    ```
    

---

## Final Words

These 12 Linux commands are super useful for DevOps beginners. They help you fix problems, manage servers, and save time. Try them out, practice with the examples, and you’ll soon feel confident using Linux!
