• We did not send an email asking for donations - please read this post.

Pulling through .PNG files from specific sub-directories in a directory

KinglyPack

New Member
Joined
May 14, 2019
Messages
1
Reaction score
0
Credits
0
Oh hai everyone,

First post, much excite...

So, I was trying to pull out all the .png images from a series of sub-directories all called 'Images', these were each within a directory with a unique name, shown with a the wildcard * below.

find /Documents/PB_Export/*/Images/ -name '*png' -print | xargs -i% mv % /Documents/PB_Export/Output/

It worked, but it pulled every .png image from every sub-directory below the wild card, not just the images folder.

What did I do wrong?

(Using Ubuntu 16...ish)

Thanks in advance!

Ollie
 


dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
1,571
Reaction score
1,191
Credits
10,043
find looks for all the files and subdirectories under which it is given.

For example find / -name myfile.txt will search every directory under /
find /Documents/PB_Export/*/Images/ -name ... will search in every subdirectory under /Documents/PB_Export/*/Images/

You can use the -maxdepth flag to limit how many subdirectories deep you want to limit the search too.
You can mix this with the -mindepth flag as well to limit how high and low you want to go.

find /usr -maxdepth 3 -name myfile.txt
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top