Getting Started with Bash Scripting: My Weekly Dev Journey πŸš€

Nishant KumarNishant Kumar
2 min read

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.gz backup file

  • The filename includes the current date

πŸ’‘ Concepts Learned:

  • Using tar for compression

  • Getting the current date using date

  • if statements to check if directories exist

  • Using mkdir to create folders

  • Bonus: 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

0
Subscribe to my newsletter

Read articles from Nishant Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nishant Kumar
Nishant Kumar

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!