find command sends subfolders even with maxdepth having value of 2?

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












-1














I have this bash command:



find . -type d -mindepth 1 -maxdepth 2 | du -h --threshold=2KB


and I got these results:



r2g: the tarball folders: 8.0K ./cli
r2g: the tarball folders: 24K ./dist/commands/ls
r2g: the tarball folders: 48K ./dist/commands/add
r2g: the tarball folders: 36K ./dist/commands/run
r2g: the tarball folders: 20K ./dist/commands/basic
r2g: the tarball folders: 36K ./dist/commands/config/local
r2g: the tarball folders: 36K ./dist/commands/config/global
r2g: the tarball folders: 92K ./dist/commands/config
r2g: the tarball folders: 4.0K ./dist/commands/find
r2g: the tarball folders: 44K ./dist/commands/init
r2g: the tarball folders: 272K ./dist/commands
r2g: the tarball folders: 416K ./dist
r2g: the tarball folders: 48K ./assets
r2g: the tarball folders: 504K .


but when this command is run by itself:



find . -type d -mindepth 1 -maxdepth 2


I only get this:



r2g: the tarball folders: ./assets
r2g: the tarball folders: ./cli
r2g: the tarball folders: ./dist
r2g: the tarball folders: ./dist/commands


anyone know what's going on? I guess the du command is showing subfolders, of the folders at depth 2, even though find is not explicitly pass them, I guess I have to limit du to a depth somehow?










share|improve this question

















  • 1




    You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
    – ctrl-alt-delor
    Dec 22 '18 at 12:31















-1














I have this bash command:



find . -type d -mindepth 1 -maxdepth 2 | du -h --threshold=2KB


and I got these results:



r2g: the tarball folders: 8.0K ./cli
r2g: the tarball folders: 24K ./dist/commands/ls
r2g: the tarball folders: 48K ./dist/commands/add
r2g: the tarball folders: 36K ./dist/commands/run
r2g: the tarball folders: 20K ./dist/commands/basic
r2g: the tarball folders: 36K ./dist/commands/config/local
r2g: the tarball folders: 36K ./dist/commands/config/global
r2g: the tarball folders: 92K ./dist/commands/config
r2g: the tarball folders: 4.0K ./dist/commands/find
r2g: the tarball folders: 44K ./dist/commands/init
r2g: the tarball folders: 272K ./dist/commands
r2g: the tarball folders: 416K ./dist
r2g: the tarball folders: 48K ./assets
r2g: the tarball folders: 504K .


but when this command is run by itself:



find . -type d -mindepth 1 -maxdepth 2


I only get this:



r2g: the tarball folders: ./assets
r2g: the tarball folders: ./cli
r2g: the tarball folders: ./dist
r2g: the tarball folders: ./dist/commands


anyone know what's going on? I guess the du command is showing subfolders, of the folders at depth 2, even though find is not explicitly pass them, I guess I have to limit du to a depth somehow?










share|improve this question

















  • 1




    You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
    – ctrl-alt-delor
    Dec 22 '18 at 12:31













-1












-1








-1







I have this bash command:



find . -type d -mindepth 1 -maxdepth 2 | du -h --threshold=2KB


and I got these results:



r2g: the tarball folders: 8.0K ./cli
r2g: the tarball folders: 24K ./dist/commands/ls
r2g: the tarball folders: 48K ./dist/commands/add
r2g: the tarball folders: 36K ./dist/commands/run
r2g: the tarball folders: 20K ./dist/commands/basic
r2g: the tarball folders: 36K ./dist/commands/config/local
r2g: the tarball folders: 36K ./dist/commands/config/global
r2g: the tarball folders: 92K ./dist/commands/config
r2g: the tarball folders: 4.0K ./dist/commands/find
r2g: the tarball folders: 44K ./dist/commands/init
r2g: the tarball folders: 272K ./dist/commands
r2g: the tarball folders: 416K ./dist
r2g: the tarball folders: 48K ./assets
r2g: the tarball folders: 504K .


but when this command is run by itself:



find . -type d -mindepth 1 -maxdepth 2


I only get this:



r2g: the tarball folders: ./assets
r2g: the tarball folders: ./cli
r2g: the tarball folders: ./dist
r2g: the tarball folders: ./dist/commands


anyone know what's going on? I guess the du command is showing subfolders, of the folders at depth 2, even though find is not explicitly pass them, I guess I have to limit du to a depth somehow?










share|improve this question













I have this bash command:



find . -type d -mindepth 1 -maxdepth 2 | du -h --threshold=2KB


and I got these results:



r2g: the tarball folders: 8.0K ./cli
r2g: the tarball folders: 24K ./dist/commands/ls
r2g: the tarball folders: 48K ./dist/commands/add
r2g: the tarball folders: 36K ./dist/commands/run
r2g: the tarball folders: 20K ./dist/commands/basic
r2g: the tarball folders: 36K ./dist/commands/config/local
r2g: the tarball folders: 36K ./dist/commands/config/global
r2g: the tarball folders: 92K ./dist/commands/config
r2g: the tarball folders: 4.0K ./dist/commands/find
r2g: the tarball folders: 44K ./dist/commands/init
r2g: the tarball folders: 272K ./dist/commands
r2g: the tarball folders: 416K ./dist
r2g: the tarball folders: 48K ./assets
r2g: the tarball folders: 504K .


but when this command is run by itself:



find . -type d -mindepth 1 -maxdepth 2


I only get this:



r2g: the tarball folders: ./assets
r2g: the tarball folders: ./cli
r2g: the tarball folders: ./dist
r2g: the tarball folders: ./dist/commands


anyone know what's going on? I guess the du command is showing subfolders, of the folders at depth 2, even though find is not explicitly pass them, I guess I have to limit du to a depth somehow?







find disk-usage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 22 '18 at 8:29









Alexander Mills

2,16411442




2,16411442







  • 1




    You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
    – ctrl-alt-delor
    Dec 22 '18 at 12:31












  • 1




    You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
    – ctrl-alt-delor
    Dec 22 '18 at 12:31







1




1




You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
– ctrl-alt-delor
Dec 22 '18 at 12:31




You show that find is doing the correct thing. You show that when you add du it does something unexpected. So is the problem in find or in du?
– ctrl-alt-delor
Dec 22 '18 at 12:31










1 Answer
1






active

oldest

votes


















0














When the du utility is given a directory pathname, it will, by default, show the size of that directory and all its subdirectories.



When not given a directory (as in your example code), it will show the size of the current directory and all its subdirectories.



You example code will not pass anything to du as the du utility does not read from standard input.



Would you want to calculate the size of each directory, then use



find . -mindepth 1 -maxdepth 2 -type d -exec du -h --threshold=2KB -s ;


Note that this will still include the size of each subdirectory in the calculation since du would recurse by itself, but with -s only the total size is shown.



Would you want to calculate the size of each directory while excluding the size of its subdirectories, then you would have to pass the filenames of the files in the directory to du explicitly. This is a bit difficult to do properly, so I'm not doing that unless it's really needed (a first draft that I attempted ended up calling find from find...)






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%2f490448%2ffind-command-sends-subfolders-even-with-maxdepth-having-value-of-2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    When the du utility is given a directory pathname, it will, by default, show the size of that directory and all its subdirectories.



    When not given a directory (as in your example code), it will show the size of the current directory and all its subdirectories.



    You example code will not pass anything to du as the du utility does not read from standard input.



    Would you want to calculate the size of each directory, then use



    find . -mindepth 1 -maxdepth 2 -type d -exec du -h --threshold=2KB -s ;


    Note that this will still include the size of each subdirectory in the calculation since du would recurse by itself, but with -s only the total size is shown.



    Would you want to calculate the size of each directory while excluding the size of its subdirectories, then you would have to pass the filenames of the files in the directory to du explicitly. This is a bit difficult to do properly, so I'm not doing that unless it's really needed (a first draft that I attempted ended up calling find from find...)






    share|improve this answer

























      0














      When the du utility is given a directory pathname, it will, by default, show the size of that directory and all its subdirectories.



      When not given a directory (as in your example code), it will show the size of the current directory and all its subdirectories.



      You example code will not pass anything to du as the du utility does not read from standard input.



      Would you want to calculate the size of each directory, then use



      find . -mindepth 1 -maxdepth 2 -type d -exec du -h --threshold=2KB -s ;


      Note that this will still include the size of each subdirectory in the calculation since du would recurse by itself, but with -s only the total size is shown.



      Would you want to calculate the size of each directory while excluding the size of its subdirectories, then you would have to pass the filenames of the files in the directory to du explicitly. This is a bit difficult to do properly, so I'm not doing that unless it's really needed (a first draft that I attempted ended up calling find from find...)






      share|improve this answer























        0












        0








        0






        When the du utility is given a directory pathname, it will, by default, show the size of that directory and all its subdirectories.



        When not given a directory (as in your example code), it will show the size of the current directory and all its subdirectories.



        You example code will not pass anything to du as the du utility does not read from standard input.



        Would you want to calculate the size of each directory, then use



        find . -mindepth 1 -maxdepth 2 -type d -exec du -h --threshold=2KB -s ;


        Note that this will still include the size of each subdirectory in the calculation since du would recurse by itself, but with -s only the total size is shown.



        Would you want to calculate the size of each directory while excluding the size of its subdirectories, then you would have to pass the filenames of the files in the directory to du explicitly. This is a bit difficult to do properly, so I'm not doing that unless it's really needed (a first draft that I attempted ended up calling find from find...)






        share|improve this answer












        When the du utility is given a directory pathname, it will, by default, show the size of that directory and all its subdirectories.



        When not given a directory (as in your example code), it will show the size of the current directory and all its subdirectories.



        You example code will not pass anything to du as the du utility does not read from standard input.



        Would you want to calculate the size of each directory, then use



        find . -mindepth 1 -maxdepth 2 -type d -exec du -h --threshold=2KB -s ;


        Note that this will still include the size of each subdirectory in the calculation since du would recurse by itself, but with -s only the total size is shown.



        Would you want to calculate the size of each directory while excluding the size of its subdirectories, then you would have to pass the filenames of the files in the directory to du explicitly. This is a bit difficult to do properly, so I'm not doing that unless it's really needed (a first draft that I attempted ended up calling find from find...)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 22 '18 at 8:49









        Kusalananda

        122k16230375




        122k16230375



























            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%2f490448%2ffind-command-sends-subfolders-even-with-maxdepth-having-value-of-2%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?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?