Getting Started with Bash Scripting: My Weekly Dev Journey π
Hi, I'm Nishantβa beginner coder and tech enthusiast. I enjoy learning and working with Python, Linux, and Git. I'm also starting to explore DevOps to learn how to build, deploy, and maintain software efficiently. I use trusted resources like Harvardβs CS50P and ChatGPT to guide my learning journey. On my Hashnode page, I share simple tips and insights about coding and DevOps practices as I grow my skills each day. Join me on my journey to learn and share knowledge!
Hey everyone! π I'm Nishant, and this week I took my first steps into the world of Bash scripting. It was a great experience that helped me understand how powerful the command line can be. Here's a quick breakdown of what I worked on!
π° Level 1: Basic System Info Script
π― Goal:
To get familiar with basic Linux commands, variables, and how to output useful system info with a simple script.
π What the Script Does:
Shows the hostname of the machine
Displays the OS name & version
Prints the system uptime
Displays free RAM and disk space
Lists currently logged-in users
π‘ Commands Used:
hostname
uname -a
uptime
free -h
df -h
who
π Script:
#!/bin/bash
echo "π Host Name:"
hostname
echo "π¦ OS Name and Info:"
uname -a
echo "β±οΈ Uptime:"
uptime
echo "π§ Free RAM and Disk Space:"
free -h
df -h
echo "π₯ Logged-in Users:"
who
π Takeaway:
These basic commands give you a powerful summary of your system with just a few lines of code. I now understand how Bash can help automate routine checks easily!
π§° Level 2: Backup Script
π― Goal:
To get hands-on with conditionals, loops, and simple automation.
π What the Script Does:
Takes a target folder (e.g.
/home/nishant/Documents)Creates a compressed
.tar.gzbackup fileThe filename includes the current date
π‘ Concepts Learned:
Using
tarfor compressionGetting the current date using
dateifstatements to check if directories existUsing
mkdirto create foldersBonus: Learned how to schedule backups using
cron
π Script:
#!/bin/bash
echo "Welcome to the backup program"
BACKUP_FILE="backup_$(date +'%Y-%m-%d_%H-%M-%S').tar.gz"
TARGET_DIR="/mnt/f/Programming/Linux/"
if [ -d "$TARGET_DIR" ]; then
echo "Backing up..."
tar -cvpzf "$BACKUP_FILE" "$TARGET_DIR"
echo "Backup Done β
"
else
echo "β Cannot create backup"
echo "Directory $TARGET_DIR does not exist"
exit 1
fi
π Resource:
I followed this helpful YouTube video and articles on GeeksforGeeks to guide me.
β What's Next?
I'm planning to dive deeper into Bash with more real-world scripts and maybe even explore cron jobs and log monitoring.
π’ Iβll be posting more on Monday, so stay tuned for the next update!
If you're new to Linux or Bash scripting, these projects are a great place to start. Simple, fun, and very practical!
Thanks for reading π
Connect with me on LinkedIn π
#bash #linux #scripting #devops #nishantcodes #learning


