In base directory i have folders like this:
1 2 3 4 5 10 110
so in each of them i have files like
0010011.mp3 0010031.mp3 0010051.mp3 0010071.mp3 0010021.mp3 0010041.mp3 0010061.mp3
so i want to remove first 3 characters and last 1 character so files will look like this
001.mp3 003.mp3 005.mp3 007.mp3 002.mp3 004.mp3 006.mp3
i tried this
for file in ??????*; do echo mv $file `echo $file | cut -c4-`; done
also this is not working in subdirectories it is just if files are in base directory
Advertisement
Answer
You may use this while loop:
cd /base/dir while IFS= read -rd '' file; do echo mv "$file" "$(sed -E 's~(.*/).{3}(.+)..~12.~' <<< "$file")" done < <(find . -type f -print0)
Once you’re satisfied with the results, remove echo
before mv
command.