# Day 4 - Linux & Shell Scripting basics

# 🔵 **1\. What is an Operating System (OS)?**

An **Operating System** is a software layer that **acts as a bridge between hardware and software**.

### ✔ OS Role

* User runs an **application** (software)
    
* Software sends request → **Operating System**
    
* OS interacts with **Hardware (CPU, RAM, Storage, IO)**
    
* Response travels back the same way
    

### ✔ Simple Definition

**OS = Medium that enables communication between Hardware and Software**

Without an OS, applications cannot use CPU/RAM or perform any tasks.

---

# 🔵 **2\. Why Linux? Why not Windows?**

Linux is the most used OS in servers & DevOps.

### ✔ Key Reasons

1. **Free / Open-source**
    
    * No licensing cost
        
2. **Secure**
    
    * No need for antivirus in most cases
        
3. **Fast & Lightweight**
    
    * Ideal for production workloads
        
4. **Stable**
    
    * Rarely crashes
        
5. **Flexible (Many Distributions)**  
    Ubuntu, CentOS, RedHat, Debian, Alpine, Fedora…
    

### ✔ Where Linux is used?

* Servers
    
* Cloud VMs
    
* Containers
    
* Kubernetes
    
* DevOps Tools (Jenkins, Docker, Ansible, GitLab CI…)
    

---

# 🔵 **3\. Linux Architecture (Simple Version)**

```plaintext
+-------------------------+
| Applications / Softwares|
+-------------------------+
| Compilers | User Process|
| System Softwares         |
+-------------------------+
| System Libraries (glibc) |
+-------------------------+
| Kernel (Heart of OS)     |
+-------------------------+
| Hardware (CPU | RAM | IO)|
+-------------------------+
```

### ✔ **Kernel Responsibilities**

1. **Device Management**
    
2. **Memory Management**
    
3. **Process Management**
    
4. **System Calls Handling**
    

---

# 🔵 **4\. What is Shell?**

Shell = Interface to talk to the Linux OS using **commands**.

* Windows → GUI
    
* Linux Servers → CLI (Command Line Interface)
    
* Popular shell → **Bash**
    

Shell allows:

* Creating files
    
* Navigating directories
    
* Managing processes
    
* Checking CPU/RAM
    
* Writing scripts (.sh)
    

---

# 🔵 **5\. Basic Linux Commands**

## 📌 Navigation

| Command | Meaning |
| --- | --- |
| `pwd` | Show current directory |
| `ls` | List files/folders |
| `ls -ltr` | List with details |
| `cd foldername` | Enter folder |
| `cd ..` | Go back |
| `cd ../..` | Go two levels back |

---

## 📌 File & Folder Operations

### ✔ Create

```plaintext
touch file.txt      # create file
mkdir folder        # create directory
```

### ✔ Edit File (VI Editor)

```plaintext
vi file.txt
```

Inside VI:

* Press **i** → insert mode
    
* Type content
    
* Press **Esc**
    
* Type **:wq** → save & exit
    

### ✔ View File

```plaintext
cat file.txt
```

### ✔ Delete

```plaintext
rm file.txt         # delete file
rm -r folder        # delete folder
```

---

# 🔵 **6\. System Monitoring Commands**

## ✔ Memory

```plaintext
free -m
```

## ✔ CPU Cores

```plaintext
nproc
```

## ✔ Disk Usage

```plaintext
df -h
```

## ✔ Combined Monitoring

```plaintext
top
```

Shows:

* CPU usage
    
* Memory usage
    
* Running processes
    

---

# 🔵 **7\. Important Commands (Quick List)**

| Purpose | Command |
| --- | --- |
| Show path | `pwd` |
| List files | `ls` |
| Detailed list | `ls -ltr` |
| Change directory | `cd` |
| Create file | `touch` |
| Create folder | `mkdir` |
| Remove file | `rm` |
| Remove folder | `rm -r` |
| Open file | `vi` |
| Print file | `cat` |
| CPU count | `nproc` |
| Memory | `free -m` |
| Disk | `df -h` |
| Process monitoring | `top` |

---

# 🔵 **8\. Why Shell Scripting in DevOps?**

Shell scripts are used for:

* Automating deployments
    
* Creating scheduled jobs (cron)
    
* Server maintenance
    
* Log monitoring
    
* Starting/stopping services
    
* CI/CD pipelines
