1

I have following folder structure:

/[randomChars]/icons/icon_[randomNumbersAndChars]

For example:

/awbwaidhawd/icons/icon_1241245
/awbwaidhawd/icons/icon_1552542
/awgawbvbbbb/icons/icon_1552542
/aawbbbbbbbb/icons/icon_1161266

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:

/icon_1241245.png
/icon_1552542.png
/icon_1552542.png
/icon_1161266.png

For that I want to use standard bash linux scripting.

How could you achieve that?

EDIT:

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:

/awbwaidhawd/avatars/

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. – Kamil Maciorowski Jan 30 at 0:12
0

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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