Learning Objectives
By the end of this lesson students should be able to:
Search and manipulate text
Process data using grep, sed and awk
Manage software packages
Use networking tools
Connect to remote systems
Write simple shell scripts
Automate tasks with cron
1. Advanced grep
Search text:
grep "error" [Link]
Case-insensitive:
grep -i error [Link]
Show line numbers:
grep -n error [Link]
Recursive search:
grep -r TODO .
Count matches:
grep -c error [Link]
2. sed – Stream Editor
Replace text:
sed 's/old/new/' [Link]
Replace all matches:
sed 's/old/new/g' [Link]
Edit file directly:
sed -i 's/localhost/[Link]/g' [Link]
Delete line 5:
sed '5d' [Link]
3. awk – Text Processing
Print first column:
awk '{print $1}' [Link]
Print first and third columns:
awk '{print $1,$3}' [Link]
CSV processing:
awk -F',' '{print $2}' [Link]
Sum values:
awk '{sum += $3} END {print sum}'
4. sort, uniq, cut and tr
Sort text:
sort [Link]
Count duplicates:
sort [Link] | uniq -c
Extract first CSV field:
cut -d',' -f1 [Link]
Convert text to uppercase:
echo "hello" | tr 'a-z' 'A-Z'
5. Package Management
Update package list:
sudo apt update
Upgrade packages:
sudo apt upgrade
Install software:
sudo apt install nginx
Remove software:
sudo apt remove nginx
Search packages:
apt search docker
6. Networking Basics
Check IP addresses:
ip addr
Check routes:
ip route
Ping a host:
ping [Link]
View listening ports:
ss -tulpn
DNS lookup:
nslookup [Link]
7. SSH
Connect to a remote server:
ssh user@server-ip
Copy file to remote server:
scp [Link] user@server:/home/user/
Generate SSH key:
ssh-keygen
View public key:
cat ~/.ssh/id_rsa.pub
8. Bash Scripting
Create script:
nano [Link]
Contents:
#!/bin/bash
echo "Hello Linux"
Make executable:
chmod +x [Link]
Run:
./[Link]
9. Variables and User Input
#!/bin/bash
echo "Enter your name:"
read NAME
echo "Hello $NAME"
10. Cron Jobs
Edit cron table:
crontab -e
Run every day at 6 AM:
0 6 * * * /home/student/[Link]
View scheduled jobs:
crontab -l
Capstone Project – Linux
Administration Toolkit
Create a Bash script that:
1. Creates project folders.
2. Backs up important files.
3. Reports disk usage.
4. Searches logs for errors.
5. Saves results to a report file.
6. Runs automatically using cron.
Summary
You can now:
Process text efficiently
Search logs and files
Install software
Use networking tools
Connect to remote systems
Write shell scripts
Automate tasks with cron
Perform basic Linux administration