4. Text Processing, Process Control & Task Scheduling
Modules 7, 8 & 9: grep, sed, awk, ps, top, kill signals, SIGTERM vs SIGKILL, crontab automation & systemd timers
Module 1: Text Processing & Regular Expressions (grep, sed, awk)
Searching, parsing, and modifying log files and configuration streams.
🇬🇧 English Definition
Linux administration constantly involves searching and transforming logs and configurations. Master grep (filtering), sed (stream editor), and awk (field-oriented processing language).
🇮🇳 Hinglish Definition
Logs aur config files ko filter/parse karne ke liye text-processing commands (grep, sed, awk) bahut important hain.
Core Concepts & Rules
- grep -i: Case-insensitive search filter.
- sed 's/old/new/g': Stream editor substituting pattern matches globally.
- awk '{print $1}': Field-oriented column extractor.
🔍 Line-by-Line Command Breakdown
- Line 1: grep 'ERROR' app.log filters lines matching ERROR.
- Line 2: cut -d: -f1 /etc/passwd extracts username field using : delimiter.
- Line 3: sed 's/old/new/g' file.txt replaces old with new stream text.
- Line 4: awk '{print $1}' access.log prints first column (IP address) from log.
🎯 Interview Focus & Questions
- Q: grep vs sed vs awk?
A: grep searches/filters text, sed edits streams, and awk is a field-oriented text-processing language.
grep "ERROR" app.log
grep -i "failed" /var/log/auth.log
cut -d: -f1 /etc/passwd
sort names.txt | uniq
wc -l file.txt
sed 's/old/new/g' file.txt
awk '{print $1}' access.log
Module 2: Processes and Job Management (ps, top, kill, signals)
Monitoring running process PIDs, CPU/RAM utilization, background jobs, and termination signals.
🇬🇧 English Definition
A process is an executing program instance. Understand PID, PPID, foreground/background jobs, nice priority levels, zombie processes, and termination signals (SIGTERM vs SIGKILL).
🇮🇳 Hinglish Definition
Process running program ka instance hota hai. CPU/memory troubleshooting ke liye process management essential hai.
Core Concepts & Rules
- SIGTERM (kill -15 PID): Requests graceful application termination.
- SIGKILL (kill -9 PID): Forces immediate kernel termination; cannot be caught or ignored.
- Zombie Process: A terminated child process whose parent has not yet collected its exit status.
🔍 Line-by-Line Command Breakdown
- Line 1: ps aux lists all active processes with user, PID, CPU%, MEM%.
- Line 2: kill -15 PID sends graceful SIGTERM signal to process.
- Line 3: kill -9 PID sends forced SIGKILL signal to process.
- Line 4: renice 10 -p PID alters scheduling priority of running process.
🎯 Interview Focus & Questions
- Q: SIGTERM vs SIGKILL?
A: SIGTERM requests graceful termination; SIGKILL forces termination and cannot be caught. - Q: What is a Zombie process?
A: A terminated child process whose parent has not yet collected its exit status. - Q: What is load average?
A: An average of runnable and uninterruptible tasks over 1, 5, and 15 minutes.
ps aux
ps -ef
top
pgrep nginx
kill -15 1234
kill -9 1234
nice -n 10 command
renice 10 -p 1234
jobs
nohup command &
Module 3: Cron & Task Scheduling Automation
Automating recurring maintenance jobs using crontab and systemd timers.
🇬🇧 English Definition
Cron automates recurring background tasks. Standard crontab fields are minute, hour, day-of-month, month, and day-of-week.
🇮🇳 Hinglish Definition
Cron recurring tasks jaise backup, cleanup aur reports automatically run karne ke liye use hota hai.
Core Concepts & Rules
- Crontab Syntax: * * * * * (minute 0-59, hour 0-23, day 1-31, month 1-12, weekday 0-7).
- Cron Environment: Uses restricted PATH and shell environment; always use absolute binary paths.
🔍 Line-by-Line Command Breakdown
- Line 1: crontab -e opens crontab file for editing.
- Line 2: crontab -l lists active cron schedule entries for user.
- Line 3: 30 2 * * * specifies execution daily at 02:30 AM.
- Line 4: */10 * * * * specifies execution every 10 minutes.
🎯 Interview Focus & Questions
- Q: Why can cron fail while a manual command works?
A: Cron has a different environment, PATH, working directory, permissions, and shell. Always use absolute paths.
crontab -l
// Daily at 02:30 AM
30 2 * * * /usr/local/bin/backup.sh
// Every 10 minutes
*/10 * * * * /usr/local/bin/check.sh
systemctl list-timers