We have wrong file names like file1@x2.png , it should be like file1@2x~ipad.png.
Not sure if this is proper place for me to raise this question. How to write the simple bash shell script to convert such file name from the wrong to the expected.
We have wrong file names like file1@x2.png , it should be like file1@2x~ipad.png.
Not sure if this is proper place for me to raise this question. How to write the simple bash shell script to convert such file name from the wrong to the expected.
using bash, although this can be translated to sh/POSIX easily
for file in *; do
[[ "$file" =~ @2x~ipad\.png$ ]] || mv "$file" "${file%@*}@2x~ipad.png"
done
if files are not just png
s then use this (extension agnostic), assuming a 3 character extension.
for file in *; do
[[ "$file" =~ @2x~ipad\.[[:alpha:]]{3}$ ]] || mv "$file" "${file%@*}@2x~ipad.${file##*.}"
done
if those files are not grouped under some dir then try to find
them recursively under a specified root dir
while read -r file; do
[[ "$file" =~ @2x~ipad\.[[:alpha:]]{3}$ ]] || mv "$file" "${file%@*}@2x~ipad.${file##*.}"
done < <(find /path/to/root/dir/to/look/under -type -f -name "*.png")
mv file1@x2.png file1@2x~ipad.png
You can use man mv
for help.
You can use prename
(comes with perl
) to do this easily for lots of files:
prename 's/x2\.png/2x~ipad.png/' *.png