I have following folder structure:


For example:


I need to grab all icon files recursively, add the file extension ".png" to them and copy them to another folder.

That means I want to achieve following result:


For that I want to use standard bash linux scripting.

How could you achieve that?


Maybe I should add that there are more subfolders in the first layer that are not important. That means there exsists for example a folder like:


Such folders should not be scanned.

Additionally, in a "icons" folder there can be files that are not named "icon_xxxxx". Those files should not be moved too.

  • What have you tried so far? Super User is not a script writing service; sole requests for code may not get much (positive) attention. If you edit the question and show your research effort (post the exact commands you tried, tell us where you are stuck) then you will increase your chances for a good answer. Jan 30 '19 at 0:12

Maybe this is a simple solution:

find /source/directory -type f -execdir cp {} `pwd`/destination/directory/\{\}.png \;

Of course you can filter it by name (--name) if you don't want copy every file. Please note if there are files with same name they will be overwritten in /destination/directory/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.