Can tree be used to list the number of files per level?

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












2















I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:



D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)


Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree accomplish this? I've tried around mixing the options but it does not seem to work.










share|improve this question
























  • tree can't do this.

    – slm
    Oct 14 '13 at 11:44















2















I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:



D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)


Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree accomplish this? I've tried around mixing the options but it does not seem to work.










share|improve this question
























  • tree can't do this.

    – slm
    Oct 14 '13 at 11:44













2












2








2


1






I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:



D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)


Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree accomplish this? I've tried around mixing the options but it does not seem to work.










share|improve this question
















I need to look into a particular directory and list the number of files per level. The directory is pretty large, about 10-15 levels deep. For instance, if I have the following:



D1
|
|-- D2A (5 files in this directory)
| |-- D3A (6 files in this directory)
| |-- D3B (7 Files in this directory)
|
|-- D2B (1 file in this directory)


Then it should tell me that level 3 has 13 files and level 2 has 6 files (or 6+13, doesn't matter). Can Tree accomplish this? I've tried around mixing the options but it does not seem to work.







directory directory-structure tree






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 10 at 19:23









Rui F Ribeiro

41.1k1479137




41.1k1479137










asked Oct 14 '13 at 9:41









gohgoh

1133




1133












  • tree can't do this.

    – slm
    Oct 14 '13 at 11:44

















  • tree can't do this.

    – slm
    Oct 14 '13 at 11:44
















tree can't do this.

– slm
Oct 14 '13 at 11:44





tree can't do this.

– slm
Oct 14 '13 at 11:44










3 Answers
3






active

oldest

votes


















2














find . -type d | 
perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '


Results:



Depth 1 has 7 files.
Depth 2 has 2353 files.
Depth 3 has 2558 files.
Depth 4 has 8242 files.
Depth 5 has 6452 files.
Depth 6 has 674 files.
Depth 7 has 1112 files.
Depth 8 has 64 files.
Depth 9 has 154 files.





share|improve this answer






























    2














    tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |


    Results:



     35 |
    186 ||
    1408 |||
    691 ||||


    The pipe (|) character indicates the depth.






    share|improve this answer






























      1














      I doubt if tree can accomplish this. However, find can:



      find . -mindepth 3 -maxdepth 3 -type f | wc -l


      would return the number of files at level 3.






      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',
        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%2f95976%2fcan-tree-be-used-to-list-the-number-of-files-per-level%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        find . -type d | 
        perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
        perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '


        Results:



        Depth 1 has 7 files.
        Depth 2 has 2353 files.
        Depth 3 has 2558 files.
        Depth 4 has 8242 files.
        Depth 5 has 6452 files.
        Depth 6 has 674 files.
        Depth 7 has 1112 files.
        Depth 8 has 64 files.
        Depth 9 has 154 files.





        share|improve this answer



























          2














          find . -type d | 
          perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
          perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '


          Results:



          Depth 1 has 7 files.
          Depth 2 has 2353 files.
          Depth 3 has 2558 files.
          Depth 4 has 8242 files.
          Depth 5 has 6452 files.
          Depth 6 has 674 files.
          Depth 7 has 1112 files.
          Depth 8 has 64 files.
          Depth 9 has 154 files.





          share|improve this answer

























            2












            2








            2







            find . -type d | 
            perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
            perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '


            Results:



            Depth 1 has 7 files.
            Depth 2 has 2353 files.
            Depth 3 has 2558 files.
            Depth 4 has 8242 files.
            Depth 5 has 6452 files.
            Depth 6 has 674 files.
            Depth 7 has 1112 files.
            Depth 8 has 64 files.
            Depth 9 has 154 files.





            share|improve this answer













            find . -type d | 
            perl -ne 'BEGIN sub cnt $file=shift; $c="find $file -maxdepth 1 -type f chomp; printf "%s %sn", $_, cnt($_)' |
            perl -ne '/^(.*) (d*)$/; $_scalar(split ///, $1)+=$2; END printf "Depth %d has %d files.n", @$_ for map [$_,$_$_] sort keys %_ '


            Results:



            Depth 1 has 7 files.
            Depth 2 has 2353 files.
            Depth 3 has 2558 files.
            Depth 4 has 8242 files.
            Depth 5 has 6452 files.
            Depth 6 has 674 files.
            Depth 7 has 1112 files.
            Depth 8 has 64 files.
            Depth 9 has 154 files.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 14 '13 at 14:26









            Stach JankowskiStach Jankowski

            361




            361























                2














                tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |


                Results:



                 35 |
                186 ||
                1408 |||
                691 ||||


                The pipe (|) character indicates the depth.






                share|improve this answer



























                  2














                  tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |


                  Results:



                   35 |
                  186 ||
                  1408 |||
                  691 ||||


                  The pipe (|) character indicates the depth.






                  share|improve this answer

























                    2












                    2








                    2







                    tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |


                    Results:



                     35 |
                    186 ||
                    1408 |||
                    691 ||||


                    The pipe (|) character indicates the depth.






                    share|improve this answer













                    tree | sed 's/ //g;s/`/|/g;s/-.*//g' | sort | uniq -c | grep |


                    Results:



                     35 |
                    186 ||
                    1408 |||
                    691 ||||


                    The pipe (|) character indicates the depth.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 14 '13 at 19:15









                    jamespfinnjamespfinn

                    35816




                    35816





















                        1














                        I doubt if tree can accomplish this. However, find can:



                        find . -mindepth 3 -maxdepth 3 -type f | wc -l


                        would return the number of files at level 3.






                        share|improve this answer



























                          1














                          I doubt if tree can accomplish this. However, find can:



                          find . -mindepth 3 -maxdepth 3 -type f | wc -l


                          would return the number of files at level 3.






                          share|improve this answer

























                            1












                            1








                            1







                            I doubt if tree can accomplish this. However, find can:



                            find . -mindepth 3 -maxdepth 3 -type f | wc -l


                            would return the number of files at level 3.






                            share|improve this answer













                            I doubt if tree can accomplish this. However, find can:



                            find . -mindepth 3 -maxdepth 3 -type f | wc -l


                            would return the number of files at level 3.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Oct 14 '13 at 10:12









                            devnulldevnull

                            8,68112942




                            8,68112942



























                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f95976%2fcan-tree-be-used-to-list-the-number-of-files-per-level%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

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

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay