I'v got a lot of PNG files and directories with PNG files in one folder. How can I replace every file with specified one using Linux command?
Notice: Backup your files before you try this. The command below will overwrite the image files on your system.
Assuming you have a directory structure like this:
a
├── a.png
├── a1.png
├── a2.png
b
├── b.png
├── b2.png
├── b3.png
MMM.png
And want to replace ALL those png files in directories /a
and /b
with the contents of MMM.png
. This command will find all the png files in those two directories and replace them with the contents of MMM.png.
find /a /b -name '*.png' -exec cp /MMM.jpg {} \;
If you need to add more directories to the list (for example /c
and /d
), just separate them with a space.
find /a /b /c /d -name '*.png' -exec cp /MMM.jpg {} \;