Getting size with du of files only












41














How can I get the size of all files and all files in its subdirectories using the du command.



I am trying the following command to get the size of all files (and files in subdirectories)



find . -type f | du -a



But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag but I am not sure how to pipe the output into another command after it executes the results of find into du.



The operating system is AIX 6.1 with ksh shell.










share|improve this question





























    41














    How can I get the size of all files and all files in its subdirectories using the du command.



    I am trying the following command to get the size of all files (and files in subdirectories)



    find . -type f | du -a



    But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag but I am not sure how to pipe the output into another command after it executes the results of find into du.



    The operating system is AIX 6.1 with ksh shell.










    share|improve this question



























      41












      41








      41


      13





      How can I get the size of all files and all files in its subdirectories using the du command.



      I am trying the following command to get the size of all files (and files in subdirectories)



      find . -type f | du -a



      But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag but I am not sure how to pipe the output into another command after it executes the results of find into du.



      The operating system is AIX 6.1 with ksh shell.










      share|improve this question















      How can I get the size of all files and all files in its subdirectories using the du command.



      I am trying the following command to get the size of all files (and files in subdirectories)



      find . -type f | du -a



      But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag but I am not sure how to pipe the output into another command after it executes the results of find into du.



      The operating system is AIX 6.1 with ksh shell.







      files find disk-usage aix ksh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 4:16









      Rui F Ribeiro

      38.9k1479129




      38.9k1479129










      asked Oct 11 '11 at 19:12









      Shardul Upadhyay

      308135




      308135






















          4 Answers
          4






          active

          oldest

          votes


















          45














          I usually use the -exec utility. Like this:



          find . -type f -exec du -a {} +


          I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec syntax.



          The following snippet sorts the list, largest first:



          find . -type f -exec du -a {} + | sort -n -r | less





          share|improve this answer



















          • 3




            I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
            – jw013
            Oct 11 '11 at 22:02






          • 1




            Updated. Thanks for the tip ^^
            – rahmu
            Oct 11 '11 at 22:05










          • Thanks, this works out great especially since du offers a flag for size in different units.
            – Shardul Upadhyay
            Oct 12 '11 at 12:59










          • I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
            – Amelio Vazquez-Reina
            Jul 19 '13 at 22:41






          • 1




            It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
            – rahmu
            Jul 20 '13 at 2:25



















          15














          If you have GNU utilities, try



          find . -type f -print0 | du --files0-from=-





          share|improve this answer























          • The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
            – Shardul Upadhyay
            Oct 11 '11 at 20:00










          • You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
            – jw013
            Oct 11 '11 at 20:04






          • 1




            Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
            – Michael Goldshteyn
            Jul 15 at 14:05



















          9














          I generally use:



          find . -type f -print0 | xargs -r0 du -a


          Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.



          Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.






          share|improve this answer

















          • 2




            The then I usually add is worth of gold :-)
            – Radek
            Oct 2 '12 at 0:56



















          2














          Here's a version with long parameter names and human sorting.



          find . -type f -exec du --human {} + | sort --human --reverse | head


          I also saw no need for -a/--all to be passed to du.






          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%2f22432%2fgetting-size-with-du-of-files-only%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            45














            I usually use the -exec utility. Like this:



            find . -type f -exec du -a {} +


            I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec syntax.



            The following snippet sorts the list, largest first:



            find . -type f -exec du -a {} + | sort -n -r | less





            share|improve this answer



















            • 3




              I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
              – jw013
              Oct 11 '11 at 22:02






            • 1




              Updated. Thanks for the tip ^^
              – rahmu
              Oct 11 '11 at 22:05










            • Thanks, this works out great especially since du offers a flag for size in different units.
              – Shardul Upadhyay
              Oct 12 '11 at 12:59










            • I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
              – Amelio Vazquez-Reina
              Jul 19 '13 at 22:41






            • 1




              It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
              – rahmu
              Jul 20 '13 at 2:25
















            45














            I usually use the -exec utility. Like this:



            find . -type f -exec du -a {} +


            I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec syntax.



            The following snippet sorts the list, largest first:



            find . -type f -exec du -a {} + | sort -n -r | less





            share|improve this answer



















            • 3




              I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
              – jw013
              Oct 11 '11 at 22:02






            • 1




              Updated. Thanks for the tip ^^
              – rahmu
              Oct 11 '11 at 22:05










            • Thanks, this works out great especially since du offers a flag for size in different units.
              – Shardul Upadhyay
              Oct 12 '11 at 12:59










            • I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
              – Amelio Vazquez-Reina
              Jul 19 '13 at 22:41






            • 1




              It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
              – rahmu
              Jul 20 '13 at 2:25














            45












            45








            45






            I usually use the -exec utility. Like this:



            find . -type f -exec du -a {} +


            I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec syntax.



            The following snippet sorts the list, largest first:



            find . -type f -exec du -a {} + | sort -n -r | less





            share|improve this answer














            I usually use the -exec utility. Like this:



            find . -type f -exec du -a {} +


            I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec syntax.



            The following snippet sorts the list, largest first:



            find . -type f -exec du -a {} + | sort -n -r | less






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 2 '13 at 22:57









            Gilles

            528k12810561583




            528k12810561583










            answered Oct 11 '11 at 21:52









            rahmu

            10.2k1969110




            10.2k1969110








            • 3




              I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
              – jw013
              Oct 11 '11 at 22:02






            • 1




              Updated. Thanks for the tip ^^
              – rahmu
              Oct 11 '11 at 22:05










            • Thanks, this works out great especially since du offers a flag for size in different units.
              – Shardul Upadhyay
              Oct 12 '11 at 12:59










            • I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
              – Amelio Vazquez-Reina
              Jul 19 '13 at 22:41






            • 1




              It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
              – rahmu
              Jul 20 '13 at 2:25














            • 3




              I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
              – jw013
              Oct 11 '11 at 22:02






            • 1




              Updated. Thanks for the tip ^^
              – rahmu
              Oct 11 '11 at 22:05










            • Thanks, this works out great especially since du offers a flag for size in different units.
              – Shardul Upadhyay
              Oct 12 '11 at 12:59










            • I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
              – Amelio Vazquez-Reina
              Jul 19 '13 at 22:41






            • 1




              It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
              – rahmu
              Jul 20 '13 at 2:25








            3




            3




            I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
            – jw013
            Oct 11 '11 at 22:02




            I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing ; with + will result in fewer invocations of du and thus better performance.
            – jw013
            Oct 11 '11 at 22:02




            1




            1




            Updated. Thanks for the tip ^^
            – rahmu
            Oct 11 '11 at 22:05




            Updated. Thanks for the tip ^^
            – rahmu
            Oct 11 '11 at 22:05












            Thanks, this works out great especially since du offers a flag for size in different units.
            – Shardul Upadhyay
            Oct 12 '11 at 12:59




            Thanks, this works out great especially since du offers a flag for size in different units.
            – Shardul Upadhyay
            Oct 12 '11 at 12:59












            I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
            – Amelio Vazquez-Reina
            Jul 19 '13 at 22:41




            I could not find information on the + option. Is that an option for du or for find ? And why does it result in less calls?
            – Amelio Vazquez-Reina
            Jul 19 '13 at 22:41




            1




            1




            It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
            – rahmu
            Jul 20 '13 at 2:25




            It's a standard option of find. It specifies to exec the command (in our case du) only once, with all the results of find given as successive arguments to the command.
            – rahmu
            Jul 20 '13 at 2:25













            15














            If you have GNU utilities, try



            find . -type f -print0 | du --files0-from=-





            share|improve this answer























            • The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
              – Shardul Upadhyay
              Oct 11 '11 at 20:00










            • You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
              – jw013
              Oct 11 '11 at 20:04






            • 1




              Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
              – Michael Goldshteyn
              Jul 15 at 14:05
















            15














            If you have GNU utilities, try



            find . -type f -print0 | du --files0-from=-





            share|improve this answer























            • The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
              – Shardul Upadhyay
              Oct 11 '11 at 20:00










            • You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
              – jw013
              Oct 11 '11 at 20:04






            • 1




              Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
              – Michael Goldshteyn
              Jul 15 at 14:05














            15












            15








            15






            If you have GNU utilities, try



            find . -type f -print0 | du --files0-from=-





            share|improve this answer














            If you have GNU utilities, try



            find . -type f -print0 | du --files0-from=-






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 11 '11 at 20:04

























            answered Oct 11 '11 at 19:43









            jw013

            35.9k699125




            35.9k699125












            • The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
              – Shardul Upadhyay
              Oct 11 '11 at 20:00










            • You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
              – jw013
              Oct 11 '11 at 20:04






            • 1




              Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
              – Michael Goldshteyn
              Jul 15 at 14:05


















            • The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
              – Shardul Upadhyay
              Oct 11 '11 at 20:00










            • You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
              – jw013
              Oct 11 '11 at 20:04






            • 1




              Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
              – Michael Goldshteyn
              Jul 15 at 14:05
















            The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
            – Shardul Upadhyay
            Oct 11 '11 at 20:00




            The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
            – Shardul Upadhyay
            Oct 11 '11 at 20:00












            You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
            – jw013
            Oct 11 '11 at 20:04




            You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
            – jw013
            Oct 11 '11 at 20:04




            1




            1




            Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
            – Michael Goldshteyn
            Jul 15 at 14:05




            Have an upvote on me! Your particular solution works with du -ch to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
            – Michael Goldshteyn
            Jul 15 at 14:05











            9














            I generally use:



            find . -type f -print0 | xargs -r0 du -a


            Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.



            Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.






            share|improve this answer

















            • 2




              The then I usually add is worth of gold :-)
              – Radek
              Oct 2 '12 at 0:56
















            9














            I generally use:



            find . -type f -print0 | xargs -r0 du -a


            Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.



            Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.






            share|improve this answer

















            • 2




              The then I usually add is worth of gold :-)
              – Radek
              Oct 2 '12 at 0:56














            9












            9








            9






            I generally use:



            find . -type f -print0 | xargs -r0 du -a


            Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.



            Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.






            share|improve this answer












            I generally use:



            find . -type f -print0 | xargs -r0 du -a


            Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.



            Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 11 '11 at 20:08









            Arcege

            16.9k44157




            16.9k44157








            • 2




              The then I usually add is worth of gold :-)
              – Radek
              Oct 2 '12 at 0:56














            • 2




              The then I usually add is worth of gold :-)
              – Radek
              Oct 2 '12 at 0:56








            2




            2




            The then I usually add is worth of gold :-)
            – Radek
            Oct 2 '12 at 0:56




            The then I usually add is worth of gold :-)
            – Radek
            Oct 2 '12 at 0:56











            2














            Here's a version with long parameter names and human sorting.



            find . -type f -exec du --human {} + | sort --human --reverse | head


            I also saw no need for -a/--all to be passed to du.






            share|improve this answer


























              2














              Here's a version with long parameter names and human sorting.



              find . -type f -exec du --human {} + | sort --human --reverse | head


              I also saw no need for -a/--all to be passed to du.






              share|improve this answer
























                2












                2








                2






                Here's a version with long parameter names and human sorting.



                find . -type f -exec du --human {} + | sort --human --reverse | head


                I also saw no need for -a/--all to be passed to du.






                share|improve this answer












                Here's a version with long parameter names and human sorting.



                find . -type f -exec du --human {} + | sort --human --reverse | head


                I also saw no need for -a/--all to be passed to du.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 7 '15 at 10:00









                Tarrasch

                1664




                1664






























                    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%2f22432%2fgetting-size-with-du-of-files-only%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