Write a shell script to rename a file.
Answers
Answered by
1
I am trying to write a script that takes a directory as a command line parameter and iterates over the files in the directory changing their extension to .bu .
I thought this would work but I'm getting the output '.bu' is not a target directory
#!/bin/bash
for f in $1; do
mv "$f".* .bu
done
I thought this would work but I'm getting the output '.bu' is not a target directory
#!/bin/bash
for f in $1; do
mv "$f".* .bu
done
Answered by
0
Answer:
#!/bin/bash
#Renaming all files from .jpg file to .jpeg file format
for file in *.jpg
do
mv "$file" "${file%.jpg}.jpeg"
done
Explanation
It searches for .jpg in the directory, if there is any file then it renames the .jpg file to .jpeg.
Similar questions