Try:
find . -type f -name '*.png' -execdir bash -c 'mv "$1" "${1%.png}@2x.png"' Move {} \;
find .
This starts a file search with the current directory.
-type f
This limits the search to regular files.
-name '*.png'
This limits the search to files whose names end with .png
.
-execdir bash -c '...' Move {} \;
This runs the command in single quotes with $0
assigned to Move
and $1
assigned to the name of the file that was found. In our case, the command in single quotes is:
mv "$1" "${1%.png}@2x.png"
This renames the file to end with @2x.png
. The construct ${1%.png}
removes the .png
from the end of the file name. Thus, ${1%.png}@2x.png
replaces the .png
at the end of the file name with @2x.png
.
Example
Let's start with directories with these files:
$ find .
.
./dirA
./dirA/fileA.png
./dirA/fileC.png
./dirA/fileB.png
./dirB
./dirB/fileE.png
./dirB/dirC
./dirB/dirC/fileF.png
./dirB/fileD.png
Now, let's run our command:
$ find . -type f -name '*.png' -execdir bash -c 'mv "$1" "${1%.png}@2x.png"' Move {} \;
After the command has executed, we now have these files:
$ find .
.
./dirA
./dirA/[email protected]
./dirA/[email protected]
./dirA/[email protected]
./dirB
./dirB/dirC
./dirB/dirC/[email protected]
./dirB/[email protected]
./dirB/[email protected]