Bash scripting is a must-have skill for Linux administrators. It lets you automate repetitive tasks and streamline system management.
Create a file called hello.sh:
#!/bin/bash
echo "Hello, World!"Make it executable and run it:
chmod +x hello.sh
./hello.shname="Linux"
echo "Hello, $name!"
# Command substitution
files=$(ls /home)
echo "Files: $files"if [ -f "/etc/passwd" ]; then
echo "File exists"
else
echo "File not found"
fi# For loop
for i in {1..5}; do
echo "Iteration $i"
done
# While loop
count=1
while [ $count -le 5 ]; do
echo "Count: $count"
((count++))
donebackup_file() {
cp "$1" "$1.bak"
echo "Backed up $1"
}
backup_file "/etc/nginx/nginx.conf"Bash scripting turns repetitive manual tasks into reliable, automated workflows. Practice by automating small tasks first.
Related Articles
Bash Scripting for Beginners
Learn the basics of Bash scripting — variables, conditionals, loops, and writing your first automation script.
CCNA Lab 4: Switch Configuration Backup to TFTP Server
Automate Cisco switch configuration backups to a remote TFTP server. Includes scripts, scheduled backups, and disaster recovery procedures.
tcpdump — Network Packet Analysis for Sysadmins
Use tcpdump to capture and analyze network traffic like a senior network engineer. Debug DNS, TCP handshakes, and slow connections.