Linux for DevOps (Beginners)
1. Linux Fundamentals
1.1 What is Open Source?
Open-source software is software whose source code is freely available for anyone to view, modify, and distribute. Linux is built on open-source principles.
- Source code is publicly accessible
- Community-driven development and contributions
- Free to use, modify, and redistribute
Examples: Linux, Python, Firefox, Android
1.2 What is Linux?
Linux is a free, open-source operating system kernel created by Linus Torvalds in 1991. It powers everything from smartphones to supercomputers.
- Linux is technically a kernel, not a full OS
- Full OS = Linux Kemel + GNU tools + package manager + desktop environment
- Popular distributions (distros): Ubuntu, Fedora, Debian, CentOS, Arch Linux
- Used in servers, cloud, Android, loT, supercomputers
1.3 Linux vs UNIX
Linux =Free, open-source, kemel by Linus Torvalds (1991)
UNIX = Proprietary OS from Bell Labs (1969), not free
Similarity = Both follow POSIX standards; Linux was inspired by UNIX
1.4 Why Use Linux?
- Free and open source - no licensing costs
- Highly secure - fewer viruses, strong permission model
- Stable and reliable - servers run for years without reboots
- Lightweight- runs on old hardware
- Industry standard - most servers, cloud, and DevOps tools run on Linux
- Customizable - choose your own components and desktop
- Manages CPU, memory, and I/O devices
- Provides system calls for programs to request services
- Acts as a bridge between applications and hardware
- Linux kernel is monolithic - all kernel services run in kemel space
- Open PowerShell as Administrator
- Run: wsl -- install
- Restart your PC
| grep 'pattern' file | Search for pattern in file |
| grep -i 'pattern' file | Case-insensitive search |
| grep -r 'pattern' dir/ | Recursive search in directory |
| grep -n 'pattern' file | Show line numbers with results |
| grep -v 'pattern' file | Show lines that do NOT match |
| grep -c 'pattern' file | Count matching lines |
| grep -E 'pllp2' file | Extended regex - match p1 OR p2 |
| find . -name ' *. txt' find / -name | Find all .txt files in current dir Find file across entire system |
| "file.log' | |
| find . -type d find . -type f find . -mtime -7 find . -size +10M | Find only directories Find only regular files Files modified in last 7 days Files larger than 10MB |
| awk '(print $1}' | Print first column of each line |
| file | |
| awk '(print $1, $3)" file | Print columns 1 and 3 |
| awk -F',' '(print $2}' file | Use comma as delimiter (CSV) |
| awk 'NR == 5' file awk '{sumt=$1) | Print line number 5 Sum all values in column 1 |
| END(print sum]' f |
| df -h du -sh <dir> | Show disk space usage (human readable) Show size of a directory |
| du -h -- max-depth=1 1sblk | Show sizes of subdirectories List block devices (disks, partitions) |
| zip archive.zip filel file2 | Create a zip archive |
| zip -r archive.zip dir/ | Zip an entire directory |
| unzip archive.zip | Extract a zip file |
| unzip -1 archive.zip | List contents without extracting |
| tar -xvf archive.tar tar -czvf archive.tar.gz diz/ | Extract a tar archive Create compressed tar.gz |
| tar -XzVf archive.tar.gz | Extract tar.gz |
| tar -tf archive.tar | List contents of tar file |
| ps | List processes for current user |
| ps aux | List ALL processes with details |
| ps aux | grep nginx top htop | Find specific process Interactive real-time process viewer Improved interactive process viewer |
| pgrep <name> | Find process ID by name |
| Command | Description |
| kill <PID> kill -9 <PID> killall <name> pkill <name> | Send SIGTERM (graceful stop) to process Send SIGKILL (force stop) to process Kill all processes by name Kill process by pattern match |
6.3 Background Jobs & nohup
| command & | Run command in background |
| jobs | List background jobs |
| fg 61 bg 41 Ctrl + Z nohup command & nohup command > out.log 2>61 & | Bring job 1 to foreground Resume job 1 in background Suspend current foreground job Run command immune to hangups (survives logout) Run nohup and save output to file |
| disown 41 | Remove job from shell job table |