Using --exclude with the du command












59















This is probably something basic but I'm not able to make it work. I'm trying to use DU to get a total size of files minus certain directories. I need to exclude one specific directory called uploads but not every directory called uploads. For example, my file structure looks a bit like this:



/store
/uploads
/junk_to_ignore
/more_junk_to_ignore
/user_one
/uploads
/user_two


I can run the following command:



du -ch --exclude=uploads* 


and it gives me the file size minus all the "uploads" directories. However, in trying to exclude certain directories (and all its sub-directories) I fail. I've tried variations of:



du -ch --exclude=./uploads*
du -ch --exclude='/full/path/to/uploads/*'


but can't seem to figure it out. How do I exclude a specific directory?










share|improve this question























  • username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

    – Kevin
    Oct 31 '11 at 18:19
















59















This is probably something basic but I'm not able to make it work. I'm trying to use DU to get a total size of files minus certain directories. I need to exclude one specific directory called uploads but not every directory called uploads. For example, my file structure looks a bit like this:



/store
/uploads
/junk_to_ignore
/more_junk_to_ignore
/user_one
/uploads
/user_two


I can run the following command:



du -ch --exclude=uploads* 


and it gives me the file size minus all the "uploads" directories. However, in trying to exclude certain directories (and all its sub-directories) I fail. I've tried variations of:



du -ch --exclude=./uploads*
du -ch --exclude='/full/path/to/uploads/*'


but can't seem to figure it out. How do I exclude a specific directory?










share|improve this question























  • username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

    – Kevin
    Oct 31 '11 at 18:19














59












59








59


11






This is probably something basic but I'm not able to make it work. I'm trying to use DU to get a total size of files minus certain directories. I need to exclude one specific directory called uploads but not every directory called uploads. For example, my file structure looks a bit like this:



/store
/uploads
/junk_to_ignore
/more_junk_to_ignore
/user_one
/uploads
/user_two


I can run the following command:



du -ch --exclude=uploads* 


and it gives me the file size minus all the "uploads" directories. However, in trying to exclude certain directories (and all its sub-directories) I fail. I've tried variations of:



du -ch --exclude=./uploads*
du -ch --exclude='/full/path/to/uploads/*'


but can't seem to figure it out. How do I exclude a specific directory?










share|improve this question














This is probably something basic but I'm not able to make it work. I'm trying to use DU to get a total size of files minus certain directories. I need to exclude one specific directory called uploads but not every directory called uploads. For example, my file structure looks a bit like this:



/store
/uploads
/junk_to_ignore
/more_junk_to_ignore
/user_one
/uploads
/user_two


I can run the following command:



du -ch --exclude=uploads* 


and it gives me the file size minus all the "uploads" directories. However, in trying to exclude certain directories (and all its sub-directories) I fail. I've tried variations of:



du -ch --exclude=./uploads*
du -ch --exclude='/full/path/to/uploads/*'


but can't seem to figure it out. How do I exclude a specific directory?







command-line disk-usage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 31 '11 at 17:47









WillWill

398135




398135













  • username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

    – Kevin
    Oct 31 '11 at 18:19



















  • username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

    – Kevin
    Oct 31 '11 at 18:19

















username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

– Kevin
Oct 31 '11 at 18:19





username: store$ du -ch --exclude=./uploads worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.

– Kevin
Oct 31 '11 at 18:19










4 Answers
4






active

oldest

votes


















79














You've almost found it :)



du -ch --exclude=./relative/path/to/uploads


Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.






share|improve this answer



















  • 4





    Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

    – Nux
    Oct 22 '14 at 17:01






  • 4





    @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

    – phatskat
    Nov 21 '14 at 15:51











  • Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

    – Nux
    Nov 23 '14 at 14:53













  • What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

    – Kiran K Telukunta
    Sep 10 '16 at 8:35











  • Why does it work with a relative path, but not an absolute path? Very odd!

    – Nick
    Feb 24 '17 at 16:55



















5














To exclude multiple directories, just pass the --exclude flag again.



du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude





share|improve this answer
























  • you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

    – Hajo Thelen
    Jul 5 '18 at 10:43





















3














awesome to skip the virtual file systems like so



du -hsx --exclude=/{proc,sys,dev} /*





share|improve this answer































    0














    If you have to be on macOS, you install GNU Coreutils with the following command.



    brew install coreutils


    Most of the commands installed by Coreutils are prefixed by g, since they have a BSD namesake preinstalled on macOS. Then you can do the following.



    gdu --exclude=Microsoft /Library/Fonts/




    share








    New contributor




    Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      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%2f23692%2fusing-exclude-with-the-du-command%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









      79














      You've almost found it :)



      du -ch --exclude=./relative/path/to/uploads


      Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.






      share|improve this answer



















      • 4





        Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

        – Nux
        Oct 22 '14 at 17:01






      • 4





        @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

        – phatskat
        Nov 21 '14 at 15:51











      • Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

        – Nux
        Nov 23 '14 at 14:53













      • What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

        – Kiran K Telukunta
        Sep 10 '16 at 8:35











      • Why does it work with a relative path, but not an absolute path? Very odd!

        – Nick
        Feb 24 '17 at 16:55
















      79














      You've almost found it :)



      du -ch --exclude=./relative/path/to/uploads


      Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.






      share|improve this answer



















      • 4





        Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

        – Nux
        Oct 22 '14 at 17:01






      • 4





        @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

        – phatskat
        Nov 21 '14 at 15:51











      • Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

        – Nux
        Nov 23 '14 at 14:53













      • What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

        – Kiran K Telukunta
        Sep 10 '16 at 8:35











      • Why does it work with a relative path, but not an absolute path? Very odd!

        – Nick
        Feb 24 '17 at 16:55














      79












      79








      79







      You've almost found it :)



      du -ch --exclude=./relative/path/to/uploads


      Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.






      share|improve this answer













      You've almost found it :)



      du -ch --exclude=./relative/path/to/uploads


      Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Oct 31 '11 at 18:25









      rozcietrzewiaczrozcietrzewiacz

      29.4k47392




      29.4k47392








      • 4





        Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

        – Nux
        Oct 22 '14 at 17:01






      • 4





        @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

        – phatskat
        Nov 21 '14 at 15:51











      • Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

        – Nux
        Nov 23 '14 at 14:53













      • What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

        – Kiran K Telukunta
        Sep 10 '16 at 8:35











      • Why does it work with a relative path, but not an absolute path? Very odd!

        – Nick
        Feb 24 '17 at 16:55














      • 4





        Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

        – Nux
        Oct 22 '14 at 17:01






      • 4





        @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

        – phatskat
        Nov 21 '14 at 15:51











      • Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

        – Nux
        Nov 23 '14 at 14:53













      • What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

        – Kiran K Telukunta
        Sep 10 '16 at 8:35











      • Why does it work with a relative path, but not an absolute path? Very odd!

        – Nick
        Feb 24 '17 at 16:55








      4




      4





      Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

      – Nux
      Oct 22 '14 at 17:01





      Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads

      – Nux
      Oct 22 '14 at 17:01




      4




      4





      @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

      – phatskat
      Nov 21 '14 at 15:51





      @Nux probably your flavor of du. Mine (OSX) doesn't even have --exclude, instead it has -I mask to "Ignore files and directories matching the specified mask." In your working example you also omit the =, making me further think it's just your version of du being slightly dufferent.

      – phatskat
      Nov 21 '14 at 15:51













      Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

      – Nux
      Nov 23 '14 at 14:53







      Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du

      – Nux
      Nov 23 '14 at 14:53















      What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

      – Kiran K Telukunta
      Sep 10 '16 at 8:35





      What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?

      – Kiran K Telukunta
      Sep 10 '16 at 8:35













      Why does it work with a relative path, but not an absolute path? Very odd!

      – Nick
      Feb 24 '17 at 16:55





      Why does it work with a relative path, but not an absolute path? Very odd!

      – Nick
      Feb 24 '17 at 16:55













      5














      To exclude multiple directories, just pass the --exclude flag again.



      du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude





      share|improve this answer
























      • you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

        – Hajo Thelen
        Jul 5 '18 at 10:43


















      5














      To exclude multiple directories, just pass the --exclude flag again.



      du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude





      share|improve this answer
























      • you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

        – Hajo Thelen
        Jul 5 '18 at 10:43
















      5












      5








      5







      To exclude multiple directories, just pass the --exclude flag again.



      du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude





      share|improve this answer













      To exclude multiple directories, just pass the --exclude flag again.



      du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 30 '17 at 21:42









      Dave NeeleyDave Neeley

      15913




      15913













      • you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

        – Hajo Thelen
        Jul 5 '18 at 10:43





















      • you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

        – Hajo Thelen
        Jul 5 '18 at 10:43



















      you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

      – Hajo Thelen
      Jul 5 '18 at 10:43







      you ca also use du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}

      – Hajo Thelen
      Jul 5 '18 at 10:43













      3














      awesome to skip the virtual file systems like so



      du -hsx --exclude=/{proc,sys,dev} /*





      share|improve this answer




























        3














        awesome to skip the virtual file systems like so



        du -hsx --exclude=/{proc,sys,dev} /*





        share|improve this answer


























          3












          3








          3







          awesome to skip the virtual file systems like so



          du -hsx --exclude=/{proc,sys,dev} /*





          share|improve this answer













          awesome to skip the virtual file systems like so



          du -hsx --exclude=/{proc,sys,dev} /*






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 18 '18 at 11:37









          Ben LutgensBen Lutgens

          1313




          1313























              0














              If you have to be on macOS, you install GNU Coreutils with the following command.



              brew install coreutils


              Most of the commands installed by Coreutils are prefixed by g, since they have a BSD namesake preinstalled on macOS. Then you can do the following.



              gdu --exclude=Microsoft /Library/Fonts/




              share








              New contributor




              Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                If you have to be on macOS, you install GNU Coreutils with the following command.



                brew install coreutils


                Most of the commands installed by Coreutils are prefixed by g, since they have a BSD namesake preinstalled on macOS. Then you can do the following.



                gdu --exclude=Microsoft /Library/Fonts/




                share








                New contributor




                Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  If you have to be on macOS, you install GNU Coreutils with the following command.



                  brew install coreutils


                  Most of the commands installed by Coreutils are prefixed by g, since they have a BSD namesake preinstalled on macOS. Then you can do the following.



                  gdu --exclude=Microsoft /Library/Fonts/




                  share








                  New contributor




                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  If you have to be on macOS, you install GNU Coreutils with the following command.



                  brew install coreutils


                  Most of the commands installed by Coreutils are prefixed by g, since they have a BSD namesake preinstalled on macOS. Then you can do the following.



                  gdu --exclude=Microsoft /Library/Fonts/





                  share








                  New contributor




                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share


                  share






                  New contributor




                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 4 mins ago









                  Lei ZhaoLei Zhao

                  11




                  11




                  New contributor




                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Lei Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      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%2f23692%2fusing-exclude-with-the-du-command%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

                      サソリ

                      広島県道265号伴広島線

                      Setup Asymptote in Texstudio