Given album name and corresponding directory, this scripts renames the jpg files with new name passed through command line
#!/bin/bash
<<doc
Name : Omprakash A Timashetti
Date : 18/08/2022
Description :Given album name and corresponding directory, this scripts renames the jpg files with new name passed through command line
Sample Execution:
Before executing the script
$ ls
DSN001.jpg DSN002.jpg DSN003.jpg DSN004.jpg DSN005.jpg
1) ./rename_album.sh day_out
All .jpg files in current directory is renamed as
day_out001.jpg day_out002.jpg day_out003.jpg day_out005.jpg day_out004.jpg
2) ./rename_album.sh
Error : Please pass the prefix name through command line.
doc
echo "Before executing the script"
ls #Get the directory content before executing the script
if [ $# -eq 1 ] #Check for command line argument
then
array=(`ls *.jpg`) #Get only .jpg file and store it in array
for i in ${array[@]}
do
num=`echo $i | tr -cd [:digit:]` #get if any digit in filename
mv $i $1$num.jpg #Change file name to new name
done
echo "All .jpg files in current directory is renamed as"
ls #All .jpg file renamed as name passed through command line
else
echo "Error : Please pass the prefix name through command line."
fi
Comments
Post a Comment