4/21/2026

Linux for DevOps (Beginners)

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

macos = UNIX-based (BSD), proprietary by Apple

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

1.5 Linux vs Windows

Cost => Linux is free; Windows requires a license
Security => Linux is free; Windows requires a license
Usage => Linux dominates servers; Windows dominates desktops
CLI => Linux is CLI-first; Windows is GUI-first
File System = > Linux: ext4, XFS; Windows: NTFS, FAT32
Software => Linux uses package managers; Windows uses installers (.exe)

1.6 What is a Kernel?

The kernel is the core of the operating system. It manages hardware resources and allows
software to communicate with hardware.
  • 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

Installing Ubuntu via WSL (Windows Subsystem for Linux)
WSL lets you run a Linux terminal directly on Windows without a VM.
  • Open PowerShell as Administrator
  • Run: wsl -- install
  • Restart your PC
Open Ubuntu from the Start Menu
 - Set username and password on first launch

Useful WSL commands:
ws1 -- list -- verbose
wsl -- set-default-version 2

# Open Linux files in Windows Explorer

# List installed distros
# Use WSL 2

explorer.exe .


3. Basic Terminal Commands
3.1 Navigation


pwd

Print Working Directory - shows current location

1s
List files and directories

1s -la
List all files (including hidden) with details

od <dir>
Change directory

cd ..
Go up one directory level

cd ~
Go to home directory

cd /
Go to root directory



3.2 File and Directory Operations

mkdir <name>
Create a new directory

mkdir -p a/b/c
Create nested directories

touch <file>
Create an empty file or update timestamp

rm <file>
Remove a file

rm -r <dir>
Remove directory and contents recursively

rm -zf <dir>
Force remove without prompts (use carefully!)

cp <src> <dst>
Copy a file

mv <arc> <dst>
Move or rename a file

cat <file>
Display file contents

less <file>
Scroll through file contents

nano <file>
Open file in nano text editor

vim <file>
Open file in vim text editor


3.3 File Permissions - chmod
Linux file permissions control who can read, write, or execute files.

Permission format: rwxrwxrwx (owner / group / others)

r=4
Read permission

w= 2
Write permission

x= 1
Execute permission

chmod 755 file
Owner: rwx, Group: r-x, Others: r-x

chmod 644 file
Owner: rw-, Group: r-, Others: r-

chmod +x file
Add execute permission for all

chmod -w file
Remove write permission



3.4 Links
Links allow multiple references to the same file.

ln <src> <link>
Create a hard link - points to same inode

ln -s <src> <link>
Create a soft (symbolic) link - like a shortcut

alias 11='1s -la'
Create a command alias (session only)

Key difference: Deleting the original breaks a soft link but NOT a hard link.



4. File Handling & Text Processing
4.1 head & tail

head <file>
Show first 10 lines of a file

head -n 20 <file>
Show first 20 lines

tail <file>
Show last 10 lines

tail -f <file>
Follow file in real-time (great for logs)



4.2 wc -Word Count

we <file>
Show lines, words, and bytes

wc -1 <file>
Count lines only

wc -w <file>
Count words only

wc -c <file>
Count bytes/characters only

4.3 sort

sort <file>
Sort lines alphabetically

sort -r <file>
Sort in reverse order

sort -n <file>
Sort numerically

sort -u <file>
Sort and remove duplicates

sort -k2 <file>
Sort by the 2nd column

4.4 grep - Search Text
grep searches for patterns in files or output.

grep 'pattern' fileSearch 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' fileExtended 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


4.6 awk Text processing
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

5. Disk management $ archives
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)

5.1 Zip/Unzip
zip archive.zip
filel file2
Create a zip archive
zip -r archive.zip
dir/
Zip an entire directory
unzip archive.zipExtract a zip file
unzip -1 archive.zipList contents without extracting


5.3 tar Tape Archive

tar -cvf archive.tar   creata a tea archive

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.tarList contents of tar file




6. Process management

6.1 View processes

psList processes for current user
ps auxList 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

6.2 Killing processes
CommandDescription
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
jobsList 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 41Remove job from shell job table





Niciun comentariu:

Linux for DevOps (Beginners)

Linux for DevOps (Beginners) 1. Linux Fundamentals 1.1 What is Open Source? Open-source software is software whose source code is freely ava...