I am trying to rename files with the same names in different subdirectories using for loop.They should be renamed according to the name of subdirectory.
Subdirectory1/File.txt
Subdirectory2/File.txt
should look like
Subdirectory1/Subdirectory1.txt
Subdirectory2/Subdirectory2.txt
I tried many commands and I am getting different errors. The last command, which I found on forum also doesn't work. Can somebody help me?
dir="Subdirectory1, Subdirectory2"
declare -i count=1 for file in "$dir"/*.txt; do
mv "$file" "${dir}/${dir} ${count}.txt"
count+=1
done
After running this, I get:
mv: cannot stat ‘/*/*.txt’: No such file or directory