Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Gokul V/Exercise3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Get today's date in YYYY-MM-DD format
today=$(date +"%Y-%m-%d")

# Find all .jpg files in the current directory
jpg_files=(*.jpg)

# Check if there are any .jpg files
if [ -z "${jpg_files[*]}" ]; then
echo "No .jpg files found in the current directory."
else
# Initialize a counter for renamed files
renamed_count=0

# Loop over all .jpg files in the current directory
for file in *.jpg; do
# Extract the filename without the extension
filename="${file%.jpg}"

# Rename the file by prepending the date
mv "$file" "${today}-${filename}.jpg"

# Increment the counter for renamed files
renamed_count=$((renamed_count + 1))
done

# Output the number of renamed files
echo "Renamed $renamed_count .jpg file(s)."
fi