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


New Member
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!



Well-Known Member
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

Members online