Searching for files within subdirectories?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?



For example:



Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad


Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.










share|improve this question



















  • 2




    Please update the question with information about what you want to search for in those directories.
    – Kusalananda
    Sep 19 at 12:08






  • 2




    Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
    – Goro
    Sep 19 at 13:11











  • Does ls */*/bad/ work to your satisfaction?
    – DopeGhoti
    Sep 19 at 16:13














up vote
0
down vote

favorite












I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?



For example:



Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad


Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.










share|improve this question



















  • 2




    Please update the question with information about what you want to search for in those directories.
    – Kusalananda
    Sep 19 at 12:08






  • 2




    Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
    – Goro
    Sep 19 at 13:11











  • Does ls */*/bad/ work to your satisfaction?
    – DopeGhoti
    Sep 19 at 16:13












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?



For example:



Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad


Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.










share|improve this question















I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?



For example:



Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad


Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.







grep solaris






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 19 at 13:14









Goro

6,16652762




6,16652762










asked Sep 19 at 10:59









James Hete

1




1







  • 2




    Please update the question with information about what you want to search for in those directories.
    – Kusalananda
    Sep 19 at 12:08






  • 2




    Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
    – Goro
    Sep 19 at 13:11











  • Does ls */*/bad/ work to your satisfaction?
    – DopeGhoti
    Sep 19 at 16:13












  • 2




    Please update the question with information about what you want to search for in those directories.
    – Kusalananda
    Sep 19 at 12:08






  • 2




    Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
    – Goro
    Sep 19 at 13:11











  • Does ls */*/bad/ work to your satisfaction?
    – DopeGhoti
    Sep 19 at 16:13







2




2




Please update the question with information about what you want to search for in those directories.
– Kusalananda
Sep 19 at 12:08




Please update the question with information about what you want to search for in those directories.
– Kusalananda
Sep 19 at 12:08




2




2




Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
– Goro
Sep 19 at 13:11





Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
– Goro
Sep 19 at 13:11













Does ls */*/bad/ work to your satisfaction?
– DopeGhoti
Sep 19 at 16:13




Does ls */*/bad/ work to your satisfaction?
– DopeGhoti
Sep 19 at 16:13










2 Answers
2






active

oldest

votes

















up vote
3
down vote













Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:



find . -maxdepth 2 -type d -name "BAD" 


or use



find . -name "*BAD*" -type f -o -name "*BAD*" -type d


explanation



the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).



Most users prefer something that looks like:



find . -name "*BAD*" -type f -o -name "*BAD*" -type d


which computes as



find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)


-name "BAD" searches for names that contain the string string anywhere in them



For simplicity:



find . -maxdepth 2 -o -name "*BAD*"





share|improve this answer


















  • 1




    but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
    – Jeff Schaller
    Sep 19 at 12:34










  • updadte the answer
    – Shervan
    Sep 19 at 12:38






  • 2




    Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
    – Jeff Schaller
    Sep 19 at 12:40






  • 1




    Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
    – Jeff Schaller
    Sep 19 at 12:43






  • 1




    I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
    – Jeff Schaller
    Sep 19 at 12:56

















up vote
2
down vote













Assuming you want to do a recursive search using find in each of the bad directories that are a level below directory called Main Directory:



find 'Main Directory'/*/bad ...rest of find options...


I've left the rest of the find options out because you never say what you want to search for.



find is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad directories.




Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:



find 'Main Directory'/*/bad -type f


If the bad directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use



'Main Directory'/*/bad/*


(where the final * is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls:



ls 'Main Directory'/*/bad/*





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469987%2fsearching-for-files-within-subdirectories%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:



    find . -maxdepth 2 -type d -name "BAD" 


    or use



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    explanation



    the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).



    Most users prefer something that looks like:



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    which computes as



    find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)


    -name "BAD" searches for names that contain the string string anywhere in them



    For simplicity:



    find . -maxdepth 2 -o -name "*BAD*"





    share|improve this answer


















    • 1




      but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
      – Jeff Schaller
      Sep 19 at 12:34










    • updadte the answer
      – Shervan
      Sep 19 at 12:38






    • 2




      Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
      – Jeff Schaller
      Sep 19 at 12:40






    • 1




      Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
      – Jeff Schaller
      Sep 19 at 12:43






    • 1




      I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
      – Jeff Schaller
      Sep 19 at 12:56














    up vote
    3
    down vote













    Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:



    find . -maxdepth 2 -type d -name "BAD" 


    or use



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    explanation



    the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).



    Most users prefer something that looks like:



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    which computes as



    find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)


    -name "BAD" searches for names that contain the string string anywhere in them



    For simplicity:



    find . -maxdepth 2 -o -name "*BAD*"





    share|improve this answer


















    • 1




      but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
      – Jeff Schaller
      Sep 19 at 12:34










    • updadte the answer
      – Shervan
      Sep 19 at 12:38






    • 2




      Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
      – Jeff Schaller
      Sep 19 at 12:40






    • 1




      Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
      – Jeff Schaller
      Sep 19 at 12:43






    • 1




      I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
      – Jeff Schaller
      Sep 19 at 12:56












    up vote
    3
    down vote










    up vote
    3
    down vote









    Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:



    find . -maxdepth 2 -type d -name "BAD" 


    or use



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    explanation



    the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).



    Most users prefer something that looks like:



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    which computes as



    find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)


    -name "BAD" searches for names that contain the string string anywhere in them



    For simplicity:



    find . -maxdepth 2 -o -name "*BAD*"





    share|improve this answer














    Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:



    find . -maxdepth 2 -type d -name "BAD" 


    or use



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    explanation



    the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).



    Most users prefer something that looks like:



    find . -name "*BAD*" -type f -o -name "*BAD*" -type d


    which computes as



    find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)


    -name "BAD" searches for names that contain the string string anywhere in them



    For simplicity:



    find . -maxdepth 2 -o -name "*BAD*"






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 19 at 13:02

























    answered Sep 19 at 11:32









    Shervan

    1659




    1659







    • 1




      but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
      – Jeff Schaller
      Sep 19 at 12:34










    • updadte the answer
      – Shervan
      Sep 19 at 12:38






    • 2




      Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
      – Jeff Schaller
      Sep 19 at 12:40






    • 1




      Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
      – Jeff Schaller
      Sep 19 at 12:43






    • 1




      I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
      – Jeff Schaller
      Sep 19 at 12:56












    • 1




      but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
      – Jeff Schaller
      Sep 19 at 12:34










    • updadte the answer
      – Shervan
      Sep 19 at 12:38






    • 2




      Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
      – Jeff Schaller
      Sep 19 at 12:40






    • 1




      Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
      – Jeff Schaller
      Sep 19 at 12:43






    • 1




      I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
      – Jeff Schaller
      Sep 19 at 12:56







    1




    1




    but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
    – Jeff Schaller
    Sep 19 at 12:34




    but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
    – Jeff Schaller
    Sep 19 at 12:34












    updadte the answer
    – Shervan
    Sep 19 at 12:38




    updadte the answer
    – Shervan
    Sep 19 at 12:38




    2




    2




    Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
    – Jeff Schaller
    Sep 19 at 12:40




    Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
    – Jeff Schaller
    Sep 19 at 12:40




    1




    1




    Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
    – Jeff Schaller
    Sep 19 at 12:43




    Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
    – Jeff Schaller
    Sep 19 at 12:43




    1




    1




    I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
    – Jeff Schaller
    Sep 19 at 12:56




    I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
    – Jeff Schaller
    Sep 19 at 12:56












    up vote
    2
    down vote













    Assuming you want to do a recursive search using find in each of the bad directories that are a level below directory called Main Directory:



    find 'Main Directory'/*/bad ...rest of find options...


    I've left the rest of the find options out because you never say what you want to search for.



    find is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad directories.




    Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:



    find 'Main Directory'/*/bad -type f


    If the bad directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use



    'Main Directory'/*/bad/*


    (where the final * is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls:



    ls 'Main Directory'/*/bad/*





    share|improve this answer


























      up vote
      2
      down vote













      Assuming you want to do a recursive search using find in each of the bad directories that are a level below directory called Main Directory:



      find 'Main Directory'/*/bad ...rest of find options...


      I've left the rest of the find options out because you never say what you want to search for.



      find is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad directories.




      Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:



      find 'Main Directory'/*/bad -type f


      If the bad directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use



      'Main Directory'/*/bad/*


      (where the final * is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls:



      ls 'Main Directory'/*/bad/*





      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        Assuming you want to do a recursive search using find in each of the bad directories that are a level below directory called Main Directory:



        find 'Main Directory'/*/bad ...rest of find options...


        I've left the rest of the find options out because you never say what you want to search for.



        find is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad directories.




        Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:



        find 'Main Directory'/*/bad -type f


        If the bad directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use



        'Main Directory'/*/bad/*


        (where the final * is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls:



        ls 'Main Directory'/*/bad/*





        share|improve this answer














        Assuming you want to do a recursive search using find in each of the bad directories that are a level below directory called Main Directory:



        find 'Main Directory'/*/bad ...rest of find options...


        I've left the rest of the find options out because you never say what you want to search for.



        find is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad directories.




        Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:



        find 'Main Directory'/*/bad -type f


        If the bad directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use



        'Main Directory'/*/bad/*


        (where the final * is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls:



        ls 'Main Directory'/*/bad/*






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 19 at 14:20

























        answered Sep 19 at 12:05









        Kusalananda

        108k14209332




        108k14209332



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469987%2fsearching-for-files-within-subdirectories%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay