du skip symbolic links











up vote
6
down vote

favorite












The default behavior of du on my system is not the proper default behavior.



If I ls my /data folder, I see (removing the stuff that isn't important):



ghs
ghsb -> ghs
hope
rssf -> roper
roper


Inside each folder is a set of folders with numbers as names. I want to get the total size of all folders named 14, so I use:



du -s /data/*/14


And I see...



161176 /data/ghs/14
161176 /data/ghsb/14
8 /data/hope/14
681564 /data/rssf/14
681564 /data/roper/14


What I want is only:



161176 /data/ghs/14
8 /data/hope/14
681564 /data/roper/14


I do not want to see the symbolic links. I've tried -L, -D, -S, etc. I always get the symbolic links. Is there a way to remove them?










share|improve this question




























    up vote
    6
    down vote

    favorite












    The default behavior of du on my system is not the proper default behavior.



    If I ls my /data folder, I see (removing the stuff that isn't important):



    ghs
    ghsb -> ghs
    hope
    rssf -> roper
    roper


    Inside each folder is a set of folders with numbers as names. I want to get the total size of all folders named 14, so I use:



    du -s /data/*/14


    And I see...



    161176 /data/ghs/14
    161176 /data/ghsb/14
    8 /data/hope/14
    681564 /data/rssf/14
    681564 /data/roper/14


    What I want is only:



    161176 /data/ghs/14
    8 /data/hope/14
    681564 /data/roper/14


    I do not want to see the symbolic links. I've tried -L, -D, -S, etc. I always get the symbolic links. Is there a way to remove them?










    share|improve this question


























      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











      The default behavior of du on my system is not the proper default behavior.



      If I ls my /data folder, I see (removing the stuff that isn't important):



      ghs
      ghsb -> ghs
      hope
      rssf -> roper
      roper


      Inside each folder is a set of folders with numbers as names. I want to get the total size of all folders named 14, so I use:



      du -s /data/*/14


      And I see...



      161176 /data/ghs/14
      161176 /data/ghsb/14
      8 /data/hope/14
      681564 /data/rssf/14
      681564 /data/roper/14


      What I want is only:



      161176 /data/ghs/14
      8 /data/hope/14
      681564 /data/roper/14


      I do not want to see the symbolic links. I've tried -L, -D, -S, etc. I always get the symbolic links. Is there a way to remove them?










      share|improve this question















      The default behavior of du on my system is not the proper default behavior.



      If I ls my /data folder, I see (removing the stuff that isn't important):



      ghs
      ghsb -> ghs
      hope
      rssf -> roper
      roper


      Inside each folder is a set of folders with numbers as names. I want to get the total size of all folders named 14, so I use:



      du -s /data/*/14


      And I see...



      161176 /data/ghs/14
      161176 /data/ghsb/14
      8 /data/hope/14
      681564 /data/rssf/14
      681564 /data/roper/14


      What I want is only:



      161176 /data/ghs/14
      8 /data/hope/14
      681564 /data/roper/14


      I do not want to see the symbolic links. I've tried -L, -D, -S, etc. I always get the symbolic links. Is there a way to remove them?







      shell symlink wildcards






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 at 18:18









      Eric Leschinski

      1,21211316




      1,21211316










      asked Sep 23 '14 at 19:19









      kainaw

      192110




      192110






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted










          This isn't du resolving the symbolic links; it's your shell.



          * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:



          du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14


          If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find (GNU version) instead:



          find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +





          share|improve this answer






























            up vote
            0
            down vote













            Make du skip symbolic links:



            du isn't smart enough to not chase links. By default find will skip symlinks. So creating an unholy alliance between find, du, awk and cat, the proper dark magic incantation becomes:



            find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}'


            Produces:




            145070492




            To force the output to be human readable:



            find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}' | awk '{ foo = $1 / 1024 / 1024 ; print foo "MB" }'


            Produces:




            138.35MB




            What's going on here:



            /home/somedirectory/      directory to search.
            -exec du -s for each result run a du -s producing bytes
            + >| /tmp/tmp.txt alliance between find and du, force overwrite tmp.txt
            first awk '...' get the first token of every line and add them up
            second awk '...' take the number and divide by 1024 twice to produce MB





            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',
              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%2f157112%2fdu-skip-symbolic-links%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








              up vote
              11
              down vote



              accepted










              This isn't du resolving the symbolic links; it's your shell.



              * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:



              du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14


              If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find (GNU version) instead:



              find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +





              share|improve this answer



























                up vote
                11
                down vote



                accepted










                This isn't du resolving the symbolic links; it's your shell.



                * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:



                du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14


                If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find (GNU version) instead:



                find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +





                share|improve this answer

























                  up vote
                  11
                  down vote



                  accepted







                  up vote
                  11
                  down vote



                  accepted






                  This isn't du resolving the symbolic links; it's your shell.



                  * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:



                  du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14


                  If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find (GNU version) instead:



                  find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +





                  share|improve this answer














                  This isn't du resolving the symbolic links; it's your shell.



                  * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is:



                  du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14


                  If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can use find (GNU version) instead:



                  find /data -mindepth 2 -maxdepth 2 -type d -name 14 -exec du -s {} +






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 23 '14 at 20:51









                  cjm

                  20.3k56873




                  20.3k56873










                  answered Sep 23 '14 at 19:30









                  Patrick

                  49.6k11126178




                  49.6k11126178
























                      up vote
                      0
                      down vote













                      Make du skip symbolic links:



                      du isn't smart enough to not chase links. By default find will skip symlinks. So creating an unholy alliance between find, du, awk and cat, the proper dark magic incantation becomes:



                      find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}'


                      Produces:




                      145070492




                      To force the output to be human readable:



                      find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}' | awk '{ foo = $1 / 1024 / 1024 ; print foo "MB" }'


                      Produces:




                      138.35MB




                      What's going on here:



                      /home/somedirectory/      directory to search.
                      -exec du -s for each result run a du -s producing bytes
                      + >| /tmp/tmp.txt alliance between find and du, force overwrite tmp.txt
                      first awk '...' get the first token of every line and add them up
                      second awk '...' take the number and divide by 1024 twice to produce MB





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        Make du skip symbolic links:



                        du isn't smart enough to not chase links. By default find will skip symlinks. So creating an unholy alliance between find, du, awk and cat, the proper dark magic incantation becomes:



                        find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}'


                        Produces:




                        145070492




                        To force the output to be human readable:



                        find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}' | awk '{ foo = $1 / 1024 / 1024 ; print foo "MB" }'


                        Produces:




                        138.35MB




                        What's going on here:



                        /home/somedirectory/      directory to search.
                        -exec du -s for each result run a du -s producing bytes
                        + >| /tmp/tmp.txt alliance between find and du, force overwrite tmp.txt
                        first awk '...' get the first token of every line and add them up
                        second awk '...' take the number and divide by 1024 twice to produce MB





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Make du skip symbolic links:



                          du isn't smart enough to not chase links. By default find will skip symlinks. So creating an unholy alliance between find, du, awk and cat, the proper dark magic incantation becomes:



                          find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}'


                          Produces:




                          145070492




                          To force the output to be human readable:



                          find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}' | awk '{ foo = $1 / 1024 / 1024 ; print foo "MB" }'


                          Produces:




                          138.35MB




                          What's going on here:



                          /home/somedirectory/      directory to search.
                          -exec du -s for each result run a du -s producing bytes
                          + >| /tmp/tmp.txt alliance between find and du, force overwrite tmp.txt
                          first awk '...' get the first token of every line and add them up
                          second awk '...' take the number and divide by 1024 twice to produce MB





                          share|improve this answer












                          Make du skip symbolic links:



                          du isn't smart enough to not chase links. By default find will skip symlinks. So creating an unholy alliance between find, du, awk and cat, the proper dark magic incantation becomes:



                          find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}'


                          Produces:




                          145070492




                          To force the output to be human readable:



                          find /home/somedirectory/ -exec du -s {} + >| /tmp/tmp.txt; cat tmp.txt | awk '{total = total + $1}END{print total}' | awk '{ foo = $1 / 1024 / 1024 ; print foo "MB" }'


                          Produces:




                          138.35MB




                          What's going on here:



                          /home/somedirectory/      directory to search.
                          -exec du -s for each result run a du -s producing bytes
                          + >| /tmp/tmp.txt alliance between find and du, force overwrite tmp.txt
                          first awk '...' get the first token of every line and add them up
                          second awk '...' take the number and divide by 1024 twice to produce MB






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 29 at 18:00









                          Eric Leschinski

                          1,21211316




                          1,21211316






























                              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%2f157112%2fdu-skip-symbolic-links%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