List directoties down one level, excluding some named directories and files












1














I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
Imagine a folder structure like this. CAPS are folders.



FOLDER 1

.hidden

TEMP

somefile

=========

=========

FOLDER 2

.hidden

TEMP

DATA1

DATA2

somefile

========

========

FOLDER 3

.hidden

TEMP

DATA1

somefile


I would like to run "insert magic command here" and end up with an output that looks like below



FOLDER 1

FOLDER 2

DATA1

DATA2

FOLDER 3

DATA1









share|improve this question





























    1














    I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
    Imagine a folder structure like this. CAPS are folders.



    FOLDER 1

    .hidden

    TEMP

    somefile

    =========

    =========

    FOLDER 2

    .hidden

    TEMP

    DATA1

    DATA2

    somefile

    ========

    ========

    FOLDER 3

    .hidden

    TEMP

    DATA1

    somefile


    I would like to run "insert magic command here" and end up with an output that looks like below



    FOLDER 1

    FOLDER 2

    DATA1

    DATA2

    FOLDER 3

    DATA1









    share|improve this question



























      1












      1








      1







      I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
      Imagine a folder structure like this. CAPS are folders.



      FOLDER 1

      .hidden

      TEMP

      somefile

      =========

      =========

      FOLDER 2

      .hidden

      TEMP

      DATA1

      DATA2

      somefile

      ========

      ========

      FOLDER 3

      .hidden

      TEMP

      DATA1

      somefile


      I would like to run "insert magic command here" and end up with an output that looks like below



      FOLDER 1

      FOLDER 2

      DATA1

      DATA2

      FOLDER 3

      DATA1









      share|improve this question















      I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
      Imagine a folder structure like this. CAPS are folders.



      FOLDER 1

      .hidden

      TEMP

      somefile

      =========

      =========

      FOLDER 2

      .hidden

      TEMP

      DATA1

      DATA2

      somefile

      ========

      ========

      FOLDER 3

      .hidden

      TEMP

      DATA1

      somefile


      I would like to run "insert magic command here" and end up with an output that looks like below



      FOLDER 1

      FOLDER 2

      DATA1

      DATA2

      FOLDER 3

      DATA1






      bash shell-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 4:15









      Rui F Ribeiro

      38.9k1479129




      38.9k1479129










      asked Oct 11 '15 at 22:01









      GTM

      184




      184






















          2 Answers
          2






          active

          oldest

          votes


















          0














          I did this to create your folder structure:



          for     f in    FOLDER 1 FOLDER 2 FOLDER 3
          do mkdir -p "$f/TEMP"
          touch "$f/.hidden" "$f/somefile"
          case "$f" in
          (*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
          (*3) mkdir -p "$f/DATA1/TEMP"
          esac
          done


          That created a tree like:



          find .




          .
          ./FOLDER 1
          ./FOLDER 1/TEMP
          ./FOLDER 1/.hidden
          ./FOLDER 1/somefile
          ./FOLDER 2
          ./FOLDER 2/TEMP
          ./FOLDER 2/.hidden
          ./FOLDER 2/somefile
          ./FOLDER 2/DATA1
          ./FOLDER 2/DATA1/TEMP
          ./FOLDER 2/DATA2
          ./FOLDER 2/DATA2/TEMP
          ./FOLDER 3
          ./FOLDER 3/TEMP
          ./FOLDER 3/.hidden
          ./FOLDER 3/somefile
          ./FOLDER 3/DATA1
          ./FOLDER 3/DATA1/TEMP


          And last I did...



          find . ! -path './*/*/*' ! -name TEMP -type d




          .
          ./FOLDER 1
          ./FOLDER 2
          ./FOLDER 2/DATA1
          ./FOLDER 2/DATA2
          ./FOLDER 3
          ./FOLDER 3/DATA1





          share|improve this answer





























            0














            Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with



            find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt


            Cleaned up the result a bit with



            sed -n -e 's;^.*/;;p'


            So it lists as



            FOLDER 1



            FOLDER 2



            DATA1



            DATA2



            FOLDER 3



            DATA1



            Finally ended up with this beast of a line



            find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt


            Might be messy but hey I'm no expert. Thanks for all the help.






            share|improve this answer





















            • If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
              – daniel kullmann
              Oct 12 '15 at 13:29












            • I did try that but couldn't get it to sort right, probably me being thick.
              – GTM
              Oct 12 '15 at 14:05











            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f235465%2flist-directoties-down-one-level-excluding-some-named-directories-and-files%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I did this to create your folder structure:



            for     f in    FOLDER 1 FOLDER 2 FOLDER 3
            do mkdir -p "$f/TEMP"
            touch "$f/.hidden" "$f/somefile"
            case "$f" in
            (*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
            (*3) mkdir -p "$f/DATA1/TEMP"
            esac
            done


            That created a tree like:



            find .




            .
            ./FOLDER 1
            ./FOLDER 1/TEMP
            ./FOLDER 1/.hidden
            ./FOLDER 1/somefile
            ./FOLDER 2
            ./FOLDER 2/TEMP
            ./FOLDER 2/.hidden
            ./FOLDER 2/somefile
            ./FOLDER 2/DATA1
            ./FOLDER 2/DATA1/TEMP
            ./FOLDER 2/DATA2
            ./FOLDER 2/DATA2/TEMP
            ./FOLDER 3
            ./FOLDER 3/TEMP
            ./FOLDER 3/.hidden
            ./FOLDER 3/somefile
            ./FOLDER 3/DATA1
            ./FOLDER 3/DATA1/TEMP


            And last I did...



            find . ! -path './*/*/*' ! -name TEMP -type d




            .
            ./FOLDER 1
            ./FOLDER 2
            ./FOLDER 2/DATA1
            ./FOLDER 2/DATA2
            ./FOLDER 3
            ./FOLDER 3/DATA1





            share|improve this answer


























              0














              I did this to create your folder structure:



              for     f in    FOLDER 1 FOLDER 2 FOLDER 3
              do mkdir -p "$f/TEMP"
              touch "$f/.hidden" "$f/somefile"
              case "$f" in
              (*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
              (*3) mkdir -p "$f/DATA1/TEMP"
              esac
              done


              That created a tree like:



              find .




              .
              ./FOLDER 1
              ./FOLDER 1/TEMP
              ./FOLDER 1/.hidden
              ./FOLDER 1/somefile
              ./FOLDER 2
              ./FOLDER 2/TEMP
              ./FOLDER 2/.hidden
              ./FOLDER 2/somefile
              ./FOLDER 2/DATA1
              ./FOLDER 2/DATA1/TEMP
              ./FOLDER 2/DATA2
              ./FOLDER 2/DATA2/TEMP
              ./FOLDER 3
              ./FOLDER 3/TEMP
              ./FOLDER 3/.hidden
              ./FOLDER 3/somefile
              ./FOLDER 3/DATA1
              ./FOLDER 3/DATA1/TEMP


              And last I did...



              find . ! -path './*/*/*' ! -name TEMP -type d




              .
              ./FOLDER 1
              ./FOLDER 2
              ./FOLDER 2/DATA1
              ./FOLDER 2/DATA2
              ./FOLDER 3
              ./FOLDER 3/DATA1





              share|improve this answer
























                0












                0








                0






                I did this to create your folder structure:



                for     f in    FOLDER 1 FOLDER 2 FOLDER 3
                do mkdir -p "$f/TEMP"
                touch "$f/.hidden" "$f/somefile"
                case "$f" in
                (*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
                (*3) mkdir -p "$f/DATA1/TEMP"
                esac
                done


                That created a tree like:



                find .




                .
                ./FOLDER 1
                ./FOLDER 1/TEMP
                ./FOLDER 1/.hidden
                ./FOLDER 1/somefile
                ./FOLDER 2
                ./FOLDER 2/TEMP
                ./FOLDER 2/.hidden
                ./FOLDER 2/somefile
                ./FOLDER 2/DATA1
                ./FOLDER 2/DATA1/TEMP
                ./FOLDER 2/DATA2
                ./FOLDER 2/DATA2/TEMP
                ./FOLDER 3
                ./FOLDER 3/TEMP
                ./FOLDER 3/.hidden
                ./FOLDER 3/somefile
                ./FOLDER 3/DATA1
                ./FOLDER 3/DATA1/TEMP


                And last I did...



                find . ! -path './*/*/*' ! -name TEMP -type d




                .
                ./FOLDER 1
                ./FOLDER 2
                ./FOLDER 2/DATA1
                ./FOLDER 2/DATA2
                ./FOLDER 3
                ./FOLDER 3/DATA1





                share|improve this answer












                I did this to create your folder structure:



                for     f in    FOLDER 1 FOLDER 2 FOLDER 3
                do mkdir -p "$f/TEMP"
                touch "$f/.hidden" "$f/somefile"
                case "$f" in
                (*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
                (*3) mkdir -p "$f/DATA1/TEMP"
                esac
                done


                That created a tree like:



                find .




                .
                ./FOLDER 1
                ./FOLDER 1/TEMP
                ./FOLDER 1/.hidden
                ./FOLDER 1/somefile
                ./FOLDER 2
                ./FOLDER 2/TEMP
                ./FOLDER 2/.hidden
                ./FOLDER 2/somefile
                ./FOLDER 2/DATA1
                ./FOLDER 2/DATA1/TEMP
                ./FOLDER 2/DATA2
                ./FOLDER 2/DATA2/TEMP
                ./FOLDER 3
                ./FOLDER 3/TEMP
                ./FOLDER 3/.hidden
                ./FOLDER 3/somefile
                ./FOLDER 3/DATA1
                ./FOLDER 3/DATA1/TEMP


                And last I did...



                find . ! -path './*/*/*' ! -name TEMP -type d




                .
                ./FOLDER 1
                ./FOLDER 2
                ./FOLDER 2/DATA1
                ./FOLDER 2/DATA2
                ./FOLDER 3
                ./FOLDER 3/DATA1






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 12 '15 at 1:37









                mikeserv

                45.3k567153




                45.3k567153

























                    0














                    Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt


                    Cleaned up the result a bit with



                    sed -n -e 's;^.*/;;p'


                    So it lists as



                    FOLDER 1



                    FOLDER 2



                    DATA1



                    DATA2



                    FOLDER 3



                    DATA1



                    Finally ended up with this beast of a line



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt


                    Might be messy but hey I'm no expert. Thanks for all the help.






                    share|improve this answer





















                    • If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                      – daniel kullmann
                      Oct 12 '15 at 13:29












                    • I did try that but couldn't get it to sort right, probably me being thick.
                      – GTM
                      Oct 12 '15 at 14:05
















                    0














                    Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt


                    Cleaned up the result a bit with



                    sed -n -e 's;^.*/;;p'


                    So it lists as



                    FOLDER 1



                    FOLDER 2



                    DATA1



                    DATA2



                    FOLDER 3



                    DATA1



                    Finally ended up with this beast of a line



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt


                    Might be messy but hey I'm no expert. Thanks for all the help.






                    share|improve this answer





















                    • If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                      – daniel kullmann
                      Oct 12 '15 at 13:29












                    • I did try that but couldn't get it to sort right, probably me being thick.
                      – GTM
                      Oct 12 '15 at 14:05














                    0












                    0








                    0






                    Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt


                    Cleaned up the result a bit with



                    sed -n -e 's;^.*/;;p'


                    So it lists as



                    FOLDER 1



                    FOLDER 2



                    DATA1



                    DATA2



                    FOLDER 3



                    DATA1



                    Finally ended up with this beast of a line



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt


                    Might be messy but hey I'm no expert. Thanks for all the help.






                    share|improve this answer












                    Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt


                    Cleaned up the result a bit with



                    sed -n -e 's;^.*/;;p'


                    So it lists as



                    FOLDER 1



                    FOLDER 2



                    DATA1



                    DATA2



                    FOLDER 3



                    DATA1



                    Finally ended up with this beast of a line



                    find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt


                    Might be messy but hey I'm no expert. Thanks for all the help.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 12 '15 at 12:00









                    GTM

                    184




                    184












                    • If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                      – daniel kullmann
                      Oct 12 '15 at 13:29












                    • I did try that but couldn't get it to sort right, probably me being thick.
                      – GTM
                      Oct 12 '15 at 14:05


















                    • If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                      – daniel kullmann
                      Oct 12 '15 at 13:29












                    • I did try that but couldn't get it to sort right, probably me being thick.
                      – GTM
                      Oct 12 '15 at 14:05
















                    If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                    – daniel kullmann
                    Oct 12 '15 at 13:29






                    If you only want the file names without path, pass -printf "%fn" to find. No need to use sed.
                    – daniel kullmann
                    Oct 12 '15 at 13:29














                    I did try that but couldn't get it to sort right, probably me being thick.
                    – GTM
                    Oct 12 '15 at 14:05




                    I did try that but couldn't get it to sort right, probably me being thick.
                    – GTM
                    Oct 12 '15 at 14:05


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f235465%2flist-directoties-down-one-level-excluding-some-named-directories-and-files%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre