Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

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

Discussion in 'Command Line' started by KinglyPack, May 14, 2019.

  1. KinglyPack

    KinglyPack New Member

    May 14, 2019
    Likes Received:
    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!


    (Log in to hide this advertisement)

  2. dos2unix

    dos2unix New Member

    May 3, 2019
    Likes Received:
    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
    wizardfromoz likes this.

Share This Page