du wrongly reports empty directory











up vote
1
down vote

favorite
1












I'm using these commands:



du -sh --apparent-size ./*
du -sh ./*


both reporting:



4.0K    ./Lightroom_catalog_from_win_backup
432M ./Lightroom catalog - wine_backup


while those directories contain:



$ll ./"Lightroom catalog - wine_backup"
total 432M
-rwxrwx--- 1 gigi gigi 432M Mar 18 2018 Lightroom 5 Catalog Linux.lrcat
-rwxrwx--- 1 gigi gigi 227 Nov 21 2015 zbackup.bat
$ll ./Lightroom_catalog_from_win_backup
total 396M
-rwxrwx--- 3 gigi gigi 396M Dec 17 09:35 Lightroom 5 Catalog Linux.lrcat
-rwxrwx--- 3 gigi gigi 227 Dec 17 09:35 zbackup.bat


Why du is reporting 4.0K for ./Lightroom_catalog_from_win_backup and how could I make it to report correctly?



PS: other system information:



$stat --file-system $HOME
File: "/home/gigi"
ID: 5b052c62a5a527bb Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 720651086 Free: 155672577 Available: 119098665
Inodes: Total: 183050240 Free: 178896289

$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial









share|improve this question




























    up vote
    1
    down vote

    favorite
    1












    I'm using these commands:



    du -sh --apparent-size ./*
    du -sh ./*


    both reporting:



    4.0K    ./Lightroom_catalog_from_win_backup
    432M ./Lightroom catalog - wine_backup


    while those directories contain:



    $ll ./"Lightroom catalog - wine_backup"
    total 432M
    -rwxrwx--- 1 gigi gigi 432M Mar 18 2018 Lightroom 5 Catalog Linux.lrcat
    -rwxrwx--- 1 gigi gigi 227 Nov 21 2015 zbackup.bat
    $ll ./Lightroom_catalog_from_win_backup
    total 396M
    -rwxrwx--- 3 gigi gigi 396M Dec 17 09:35 Lightroom 5 Catalog Linux.lrcat
    -rwxrwx--- 3 gigi gigi 227 Dec 17 09:35 zbackup.bat


    Why du is reporting 4.0K for ./Lightroom_catalog_from_win_backup and how could I make it to report correctly?



    PS: other system information:



    $stat --file-system $HOME
    File: "/home/gigi"
    ID: 5b052c62a5a527bb Namelen: 255 Type: ext2/ext3
    Block size: 4096 Fundamental block size: 4096
    Blocks: Total: 720651086 Free: 155672577 Available: 119098665
    Inodes: Total: 183050240 Free: 178896289

    $lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 16.04.5 LTS
    Release: 16.04
    Codename: xenial









    share|improve this question


























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I'm using these commands:



      du -sh --apparent-size ./*
      du -sh ./*


      both reporting:



      4.0K    ./Lightroom_catalog_from_win_backup
      432M ./Lightroom catalog - wine_backup


      while those directories contain:



      $ll ./"Lightroom catalog - wine_backup"
      total 432M
      -rwxrwx--- 1 gigi gigi 432M Mar 18 2018 Lightroom 5 Catalog Linux.lrcat
      -rwxrwx--- 1 gigi gigi 227 Nov 21 2015 zbackup.bat
      $ll ./Lightroom_catalog_from_win_backup
      total 396M
      -rwxrwx--- 3 gigi gigi 396M Dec 17 09:35 Lightroom 5 Catalog Linux.lrcat
      -rwxrwx--- 3 gigi gigi 227 Dec 17 09:35 zbackup.bat


      Why du is reporting 4.0K for ./Lightroom_catalog_from_win_backup and how could I make it to report correctly?



      PS: other system information:



      $stat --file-system $HOME
      File: "/home/gigi"
      ID: 5b052c62a5a527bb Namelen: 255 Type: ext2/ext3
      Block size: 4096 Fundamental block size: 4096
      Blocks: Total: 720651086 Free: 155672577 Available: 119098665
      Inodes: Total: 183050240 Free: 178896289

      $lsb_release -a
      No LSB modules are available.
      Distributor ID: Ubuntu
      Description: Ubuntu 16.04.5 LTS
      Release: 16.04
      Codename: xenial









      share|improve this question















      I'm using these commands:



      du -sh --apparent-size ./*
      du -sh ./*


      both reporting:



      4.0K    ./Lightroom_catalog_from_win_backup
      432M ./Lightroom catalog - wine_backup


      while those directories contain:



      $ll ./"Lightroom catalog - wine_backup"
      total 432M
      -rwxrwx--- 1 gigi gigi 432M Mar 18 2018 Lightroom 5 Catalog Linux.lrcat
      -rwxrwx--- 1 gigi gigi 227 Nov 21 2015 zbackup.bat
      $ll ./Lightroom_catalog_from_win_backup
      total 396M
      -rwxrwx--- 3 gigi gigi 396M Dec 17 09:35 Lightroom 5 Catalog Linux.lrcat
      -rwxrwx--- 3 gigi gigi 227 Dec 17 09:35 zbackup.bat


      Why du is reporting 4.0K for ./Lightroom_catalog_from_win_backup and how could I make it to report correctly?



      PS: other system information:



      $stat --file-system $HOME
      File: "/home/gigi"
      ID: 5b052c62a5a527bb Namelen: 255 Type: ext2/ext3
      Block size: 4096 Fundamental block size: 4096
      Blocks: Total: 720651086 Free: 155672577 Available: 119098665
      Inodes: Total: 183050240 Free: 178896289

      $lsb_release -a
      No LSB modules are available.
      Distributor ID: Ubuntu
      Description: Ubuntu 16.04.5 LTS
      Release: 16.04
      Codename: xenial






      disk-usage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 9 mins ago

























      asked 24 mins ago









      adrhc

      1567




      1567






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I can reproduce if the files are hard links:



          ~ mkdir foo bar
          ~ dd if=/dev/urandom of=bar/file1 count=1k bs=1k
          1024+0 records in
          1024+0 records out
          1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00985276 s, 106 MB/s
          ~ ln bar/file1 foo/file1
          ~ du -sh --apparent-size foo bar
          1.1M foo
          4.0K bar


          This is expected behaviour. From the GNU du docs:




          If two or more hard links point to the same file, only one of the hard
          links is counted. The file argument order affects which links are
          counted, and changing the argument order may change the numbers and
          entries that du outputs.




          If you really need repeated sizes of hard links, try the -l option:




          -l

          --count-links

          Count the size of all files, even if they have appeared already (as a
          hard link).




          ~ du -sh --apparent-size foo bar -l
          1.1M foo
          1.1M bar





          share|improve this answer




























            up vote
            1
            down vote













            Notice how the link count is 3 for the two files Lightroom 5 Catalog Linux.lrcat and zbackup.bat in Lightroom_catalog_from_win_backup.



            This means that these two files are hard linked to (additional names for) other files somewhere. When you run du on a directory or a set of files, each hard link is only counted once.



            Example:



            $ ls -l
            total 41024
            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file1
            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file2

            $ du -h file1
            10.0M file1

            $ du -h file2
            10.0M file2

            $ du -h .
            10.0M .




            share




























              up vote
              0
              down vote













              It's almost certainly working correctly. du counts each file only once regardless of how many times it's referenced. It's probable that your two directories contain the same set of hard-linked files.



              The man page for GNU du offers -l, --count-links to switch off this standard optimisation (see man du to check if your implementation includes this). Or you run du twice, once for each directory.





              share





















                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%2f489421%2fdu-wrongly-reports-empty-directory%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                1
                down vote



                accepted










                I can reproduce if the files are hard links:



                ~ mkdir foo bar
                ~ dd if=/dev/urandom of=bar/file1 count=1k bs=1k
                1024+0 records in
                1024+0 records out
                1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00985276 s, 106 MB/s
                ~ ln bar/file1 foo/file1
                ~ du -sh --apparent-size foo bar
                1.1M foo
                4.0K bar


                This is expected behaviour. From the GNU du docs:




                If two or more hard links point to the same file, only one of the hard
                links is counted. The file argument order affects which links are
                counted, and changing the argument order may change the numbers and
                entries that du outputs.




                If you really need repeated sizes of hard links, try the -l option:




                -l

                --count-links

                Count the size of all files, even if they have appeared already (as a
                hard link).




                ~ du -sh --apparent-size foo bar -l
                1.1M foo
                1.1M bar





                share|improve this answer

























                  up vote
                  1
                  down vote



                  accepted










                  I can reproduce if the files are hard links:



                  ~ mkdir foo bar
                  ~ dd if=/dev/urandom of=bar/file1 count=1k bs=1k
                  1024+0 records in
                  1024+0 records out
                  1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00985276 s, 106 MB/s
                  ~ ln bar/file1 foo/file1
                  ~ du -sh --apparent-size foo bar
                  1.1M foo
                  4.0K bar


                  This is expected behaviour. From the GNU du docs:




                  If two or more hard links point to the same file, only one of the hard
                  links is counted. The file argument order affects which links are
                  counted, and changing the argument order may change the numbers and
                  entries that du outputs.




                  If you really need repeated sizes of hard links, try the -l option:




                  -l

                  --count-links

                  Count the size of all files, even if they have appeared already (as a
                  hard link).




                  ~ du -sh --apparent-size foo bar -l
                  1.1M foo
                  1.1M bar





                  share|improve this answer























                    up vote
                    1
                    down vote



                    accepted







                    up vote
                    1
                    down vote



                    accepted






                    I can reproduce if the files are hard links:



                    ~ mkdir foo bar
                    ~ dd if=/dev/urandom of=bar/file1 count=1k bs=1k
                    1024+0 records in
                    1024+0 records out
                    1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00985276 s, 106 MB/s
                    ~ ln bar/file1 foo/file1
                    ~ du -sh --apparent-size foo bar
                    1.1M foo
                    4.0K bar


                    This is expected behaviour. From the GNU du docs:




                    If two or more hard links point to the same file, only one of the hard
                    links is counted. The file argument order affects which links are
                    counted, and changing the argument order may change the numbers and
                    entries that du outputs.




                    If you really need repeated sizes of hard links, try the -l option:




                    -l

                    --count-links

                    Count the size of all files, even if they have appeared already (as a
                    hard link).




                    ~ du -sh --apparent-size foo bar -l
                    1.1M foo
                    1.1M bar





                    share|improve this answer












                    I can reproduce if the files are hard links:



                    ~ mkdir foo bar
                    ~ dd if=/dev/urandom of=bar/file1 count=1k bs=1k
                    1024+0 records in
                    1024+0 records out
                    1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00985276 s, 106 MB/s
                    ~ ln bar/file1 foo/file1
                    ~ du -sh --apparent-size foo bar
                    1.1M foo
                    4.0K bar


                    This is expected behaviour. From the GNU du docs:




                    If two or more hard links point to the same file, only one of the hard
                    links is counted. The file argument order affects which links are
                    counted, and changing the argument order may change the numbers and
                    entries that du outputs.




                    If you really need repeated sizes of hard links, try the -l option:




                    -l

                    --count-links

                    Count the size of all files, even if they have appeared already (as a
                    hard link).




                    ~ du -sh --apparent-size foo bar -l
                    1.1M foo
                    1.1M bar






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 12 mins ago









                    muru

                    35.5k583158




                    35.5k583158
























                        up vote
                        1
                        down vote













                        Notice how the link count is 3 for the two files Lightroom 5 Catalog Linux.lrcat and zbackup.bat in Lightroom_catalog_from_win_backup.



                        This means that these two files are hard linked to (additional names for) other files somewhere. When you run du on a directory or a set of files, each hard link is only counted once.



                        Example:



                        $ ls -l
                        total 41024
                        -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file1
                        -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file2

                        $ du -h file1
                        10.0M file1

                        $ du -h file2
                        10.0M file2

                        $ du -h .
                        10.0M .




                        share

























                          up vote
                          1
                          down vote













                          Notice how the link count is 3 for the two files Lightroom 5 Catalog Linux.lrcat and zbackup.bat in Lightroom_catalog_from_win_backup.



                          This means that these two files are hard linked to (additional names for) other files somewhere. When you run du on a directory or a set of files, each hard link is only counted once.



                          Example:



                          $ ls -l
                          total 41024
                          -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file1
                          -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file2

                          $ du -h file1
                          10.0M file1

                          $ du -h file2
                          10.0M file2

                          $ du -h .
                          10.0M .




                          share























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Notice how the link count is 3 for the two files Lightroom 5 Catalog Linux.lrcat and zbackup.bat in Lightroom_catalog_from_win_backup.



                            This means that these two files are hard linked to (additional names for) other files somewhere. When you run du on a directory or a set of files, each hard link is only counted once.



                            Example:



                            $ ls -l
                            total 41024
                            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file1
                            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file2

                            $ du -h file1
                            10.0M file1

                            $ du -h file2
                            10.0M file2

                            $ du -h .
                            10.0M .




                            share












                            Notice how the link count is 3 for the two files Lightroom 5 Catalog Linux.lrcat and zbackup.bat in Lightroom_catalog_from_win_backup.



                            This means that these two files are hard linked to (additional names for) other files somewhere. When you run du on a directory or a set of files, each hard link is only counted once.



                            Example:



                            $ ls -l
                            total 41024
                            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file1
                            -rw-r--r-- 2 kk wheel 10485760 Dec 17 09:07 file2

                            $ du -h file1
                            10.0M file1

                            $ du -h file2
                            10.0M file2

                            $ du -h .
                            10.0M .





                            share











                            share


                            share










                            answered 9 mins ago









                            Kusalananda

                            120k16225369




                            120k16225369






















                                up vote
                                0
                                down vote













                                It's almost certainly working correctly. du counts each file only once regardless of how many times it's referenced. It's probable that your two directories contain the same set of hard-linked files.



                                The man page for GNU du offers -l, --count-links to switch off this standard optimisation (see man du to check if your implementation includes this). Or you run du twice, once for each directory.





                                share

























                                  up vote
                                  0
                                  down vote













                                  It's almost certainly working correctly. du counts each file only once regardless of how many times it's referenced. It's probable that your two directories contain the same set of hard-linked files.



                                  The man page for GNU du offers -l, --count-links to switch off this standard optimisation (see man du to check if your implementation includes this). Or you run du twice, once for each directory.





                                  share























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    It's almost certainly working correctly. du counts each file only once regardless of how many times it's referenced. It's probable that your two directories contain the same set of hard-linked files.



                                    The man page for GNU du offers -l, --count-links to switch off this standard optimisation (see man du to check if your implementation includes this). Or you run du twice, once for each directory.





                                    share












                                    It's almost certainly working correctly. du counts each file only once regardless of how many times it's referenced. It's probable that your two directories contain the same set of hard-linked files.



                                    The man page for GNU du offers -l, --count-links to switch off this standard optimisation (see man du to check if your implementation includes this). Or you run du twice, once for each directory.






                                    share











                                    share


                                    share










                                    answered 8 mins ago









                                    roaima

                                    42.5k551116




                                    42.5k551116






























                                        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%2f489421%2fdu-wrongly-reports-empty-directory%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

                                        flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                        Mangá

                                        Eduardo VII do Reino Unido