user8650320 user8650320 - 3 years ago 250
Linux Question

Replace many PNG files with specified one

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?

Answer Source

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.png
├── a1.png
├── a2.png
├── b.png
├── b2.png
├── b3.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 {}  \;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download