Really weird ```du``` behaivour

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











up vote
-2
down vote

favorite












I want to print the size of a file from some folder /etc/*.conf in this case.



When I use:



cd /etc

du -ch $(ls | grep .conf) | tail -1 | cut -f1


I get 120K.



When I use:



du -bch $(ls | grep .conf) | tail -1 | cut -f1


I get 46K. and this should be the same size but in bytes right? so it should be some kind of 120000, right?



When i use:



du -bsh $(ls | grep .conf) | tail -1 | cut -f1


I get 1.3K, what is this man?










share|improve this question























  • Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
    – Romeo Ninov
    Nov 21 at 10:42










  • @RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
    – C. Cristi
    Nov 21 at 10:46










  • This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
    – Romeo Ninov
    Nov 21 at 10:50














up vote
-2
down vote

favorite












I want to print the size of a file from some folder /etc/*.conf in this case.



When I use:



cd /etc

du -ch $(ls | grep .conf) | tail -1 | cut -f1


I get 120K.



When I use:



du -bch $(ls | grep .conf) | tail -1 | cut -f1


I get 46K. and this should be the same size but in bytes right? so it should be some kind of 120000, right?



When i use:



du -bsh $(ls | grep .conf) | tail -1 | cut -f1


I get 1.3K, what is this man?










share|improve this question























  • Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
    – Romeo Ninov
    Nov 21 at 10:42










  • @RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
    – C. Cristi
    Nov 21 at 10:46










  • This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
    – Romeo Ninov
    Nov 21 at 10:50












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I want to print the size of a file from some folder /etc/*.conf in this case.



When I use:



cd /etc

du -ch $(ls | grep .conf) | tail -1 | cut -f1


I get 120K.



When I use:



du -bch $(ls | grep .conf) | tail -1 | cut -f1


I get 46K. and this should be the same size but in bytes right? so it should be some kind of 120000, right?



When i use:



du -bsh $(ls | grep .conf) | tail -1 | cut -f1


I get 1.3K, what is this man?










share|improve this question















I want to print the size of a file from some folder /etc/*.conf in this case.



When I use:



cd /etc

du -ch $(ls | grep .conf) | tail -1 | cut -f1


I get 120K.



When I use:



du -bch $(ls | grep .conf) | tail -1 | cut -f1


I get 46K. and this should be the same size but in bytes right? so it should be some kind of 120000, right?



When i use:



du -bsh $(ls | grep .conf) | tail -1 | cut -f1


I get 1.3K, what is this man?







shell-script shell size






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 12:58









Michael Prokopec

59315




59315










asked Nov 21 at 10:28









C. Cristi

1647




1647











  • Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
    – Romeo Ninov
    Nov 21 at 10:42










  • @RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
    – C. Cristi
    Nov 21 at 10:46










  • This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
    – Romeo Ninov
    Nov 21 at 10:50
















  • Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
    – Romeo Ninov
    Nov 21 at 10:42










  • @RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
    – C. Cristi
    Nov 21 at 10:46










  • This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
    – Romeo Ninov
    Nov 21 at 10:50















Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
– Romeo Ninov
Nov 21 at 10:42




Why you do not use the answers from your previous question? unix.stackexchange.com/questions/483135/…
– Romeo Ninov
Nov 21 at 10:42












@RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
– C. Cristi
Nov 21 at 10:46




@RomeoNinov it's not like that, if I use that I don't think it gives me the right size amount, and I need just an explanation here
– C. Cristi
Nov 21 at 10:46












This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
– Romeo Ninov
Nov 21 at 10:50




This seems like xyproblem.info . Please create new question with the real problem, not the way you think you can resolve it.
– Romeo Ninov
Nov 21 at 10:50










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










du -hc rounds out the size of the smaller files to the block size of the filesystem, typically 4K.



[root@testvm1 etc]# du -hc *.conf
4.0K asound.conf
4.0K chrony.conf
4.0K dracut.conf
....
4.0K vconsole.conf
4.0K yum.conf
104K total


du -bch avoids the rounding, which results in a lower total:



[root@testvm1 etc]# du -bch *.conf
55 asound.conf
1.1K chrony.conf
1.3K dracut.conf
....
41 vconsole.conf
970 yum.conf
32K total


du -sh does not print a total value at the end. The output of your du -bsh command will most likely be the size of the last file in list.




The -b option is equivalent to --apparent-size --block-size=1. To use block-size calculations while keeping the unit as bytes, use only the --block-size option.



[root@testvm1 etc]# du --block-size=1 -c *.conf
4096 asound.conf
4096 chrony.conf
4096 dracut.conf
...
4096 vconsole.conf
4096 yum.conf
106496 total





share|improve this answer






















  • I see and what do I do if I have to display du -hc in bytes?
    – C. Cristi
    Nov 21 at 10:55










  • du -bc will show all of the file sizes and the grand total in bytes.
    – Haxiel
    Nov 21 at 10:59










  • I want the rounded size, with hc in bytes, how can I do that
    – C. Cristi
    Nov 21 at 11:22










  • @C.Cristi Please see the edit.
    – Haxiel
    Nov 21 at 12:15










  • It has nothing to do with rounding. Haxiel, good edit! @Haxiel
    – Michael Prokopec
    Nov 21 at 12:35


















up vote
1
down vote













You should check the result of du without the | tail -1 | cut -1



(ignoring the -h option which just add the k, M...)



(based on http://man7.org/linux/man-pages/man1/du.1.html)



-c will print the disk usage of all files plus a total. note that depending of your filesystem format disk usage of a file will be bigger than its real size)



-bc will print the "real" size rather than the size its use on the disk.



-bs will only print the total "real" size of each file/folder given to du. Since you dive du each file it will calculate the size of each *.conf file and your last line is the size of the last *.conf file you've given him.



PS: you can probably do: du -bch *.conf rather than the grep on ls result.






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%2f483173%2freally-weird-du-behaivour%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
    2
    down vote



    accepted










    du -hc rounds out the size of the smaller files to the block size of the filesystem, typically 4K.



    [root@testvm1 etc]# du -hc *.conf
    4.0K asound.conf
    4.0K chrony.conf
    4.0K dracut.conf
    ....
    4.0K vconsole.conf
    4.0K yum.conf
    104K total


    du -bch avoids the rounding, which results in a lower total:



    [root@testvm1 etc]# du -bch *.conf
    55 asound.conf
    1.1K chrony.conf
    1.3K dracut.conf
    ....
    41 vconsole.conf
    970 yum.conf
    32K total


    du -sh does not print a total value at the end. The output of your du -bsh command will most likely be the size of the last file in list.




    The -b option is equivalent to --apparent-size --block-size=1. To use block-size calculations while keeping the unit as bytes, use only the --block-size option.



    [root@testvm1 etc]# du --block-size=1 -c *.conf
    4096 asound.conf
    4096 chrony.conf
    4096 dracut.conf
    ...
    4096 vconsole.conf
    4096 yum.conf
    106496 total





    share|improve this answer






















    • I see and what do I do if I have to display du -hc in bytes?
      – C. Cristi
      Nov 21 at 10:55










    • du -bc will show all of the file sizes and the grand total in bytes.
      – Haxiel
      Nov 21 at 10:59










    • I want the rounded size, with hc in bytes, how can I do that
      – C. Cristi
      Nov 21 at 11:22










    • @C.Cristi Please see the edit.
      – Haxiel
      Nov 21 at 12:15










    • It has nothing to do with rounding. Haxiel, good edit! @Haxiel
      – Michael Prokopec
      Nov 21 at 12:35















    up vote
    2
    down vote



    accepted










    du -hc rounds out the size of the smaller files to the block size of the filesystem, typically 4K.



    [root@testvm1 etc]# du -hc *.conf
    4.0K asound.conf
    4.0K chrony.conf
    4.0K dracut.conf
    ....
    4.0K vconsole.conf
    4.0K yum.conf
    104K total


    du -bch avoids the rounding, which results in a lower total:



    [root@testvm1 etc]# du -bch *.conf
    55 asound.conf
    1.1K chrony.conf
    1.3K dracut.conf
    ....
    41 vconsole.conf
    970 yum.conf
    32K total


    du -sh does not print a total value at the end. The output of your du -bsh command will most likely be the size of the last file in list.




    The -b option is equivalent to --apparent-size --block-size=1. To use block-size calculations while keeping the unit as bytes, use only the --block-size option.



    [root@testvm1 etc]# du --block-size=1 -c *.conf
    4096 asound.conf
    4096 chrony.conf
    4096 dracut.conf
    ...
    4096 vconsole.conf
    4096 yum.conf
    106496 total





    share|improve this answer






















    • I see and what do I do if I have to display du -hc in bytes?
      – C. Cristi
      Nov 21 at 10:55










    • du -bc will show all of the file sizes and the grand total in bytes.
      – Haxiel
      Nov 21 at 10:59










    • I want the rounded size, with hc in bytes, how can I do that
      – C. Cristi
      Nov 21 at 11:22










    • @C.Cristi Please see the edit.
      – Haxiel
      Nov 21 at 12:15










    • It has nothing to do with rounding. Haxiel, good edit! @Haxiel
      – Michael Prokopec
      Nov 21 at 12:35













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    du -hc rounds out the size of the smaller files to the block size of the filesystem, typically 4K.



    [root@testvm1 etc]# du -hc *.conf
    4.0K asound.conf
    4.0K chrony.conf
    4.0K dracut.conf
    ....
    4.0K vconsole.conf
    4.0K yum.conf
    104K total


    du -bch avoids the rounding, which results in a lower total:



    [root@testvm1 etc]# du -bch *.conf
    55 asound.conf
    1.1K chrony.conf
    1.3K dracut.conf
    ....
    41 vconsole.conf
    970 yum.conf
    32K total


    du -sh does not print a total value at the end. The output of your du -bsh command will most likely be the size of the last file in list.




    The -b option is equivalent to --apparent-size --block-size=1. To use block-size calculations while keeping the unit as bytes, use only the --block-size option.



    [root@testvm1 etc]# du --block-size=1 -c *.conf
    4096 asound.conf
    4096 chrony.conf
    4096 dracut.conf
    ...
    4096 vconsole.conf
    4096 yum.conf
    106496 total





    share|improve this answer














    du -hc rounds out the size of the smaller files to the block size of the filesystem, typically 4K.



    [root@testvm1 etc]# du -hc *.conf
    4.0K asound.conf
    4.0K chrony.conf
    4.0K dracut.conf
    ....
    4.0K vconsole.conf
    4.0K yum.conf
    104K total


    du -bch avoids the rounding, which results in a lower total:



    [root@testvm1 etc]# du -bch *.conf
    55 asound.conf
    1.1K chrony.conf
    1.3K dracut.conf
    ....
    41 vconsole.conf
    970 yum.conf
    32K total


    du -sh does not print a total value at the end. The output of your du -bsh command will most likely be the size of the last file in list.




    The -b option is equivalent to --apparent-size --block-size=1. To use block-size calculations while keeping the unit as bytes, use only the --block-size option.



    [root@testvm1 etc]# du --block-size=1 -c *.conf
    4096 asound.conf
    4096 chrony.conf
    4096 dracut.conf
    ...
    4096 vconsole.conf
    4096 yum.conf
    106496 total






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 21 at 12:15

























    answered Nov 21 at 10:52









    Haxiel

    47638




    47638











    • I see and what do I do if I have to display du -hc in bytes?
      – C. Cristi
      Nov 21 at 10:55










    • du -bc will show all of the file sizes and the grand total in bytes.
      – Haxiel
      Nov 21 at 10:59










    • I want the rounded size, with hc in bytes, how can I do that
      – C. Cristi
      Nov 21 at 11:22










    • @C.Cristi Please see the edit.
      – Haxiel
      Nov 21 at 12:15










    • It has nothing to do with rounding. Haxiel, good edit! @Haxiel
      – Michael Prokopec
      Nov 21 at 12:35

















    • I see and what do I do if I have to display du -hc in bytes?
      – C. Cristi
      Nov 21 at 10:55










    • du -bc will show all of the file sizes and the grand total in bytes.
      – Haxiel
      Nov 21 at 10:59










    • I want the rounded size, with hc in bytes, how can I do that
      – C. Cristi
      Nov 21 at 11:22










    • @C.Cristi Please see the edit.
      – Haxiel
      Nov 21 at 12:15










    • It has nothing to do with rounding. Haxiel, good edit! @Haxiel
      – Michael Prokopec
      Nov 21 at 12:35
















    I see and what do I do if I have to display du -hc in bytes?
    – C. Cristi
    Nov 21 at 10:55




    I see and what do I do if I have to display du -hc in bytes?
    – C. Cristi
    Nov 21 at 10:55












    du -bc will show all of the file sizes and the grand total in bytes.
    – Haxiel
    Nov 21 at 10:59




    du -bc will show all of the file sizes and the grand total in bytes.
    – Haxiel
    Nov 21 at 10:59












    I want the rounded size, with hc in bytes, how can I do that
    – C. Cristi
    Nov 21 at 11:22




    I want the rounded size, with hc in bytes, how can I do that
    – C. Cristi
    Nov 21 at 11:22












    @C.Cristi Please see the edit.
    – Haxiel
    Nov 21 at 12:15




    @C.Cristi Please see the edit.
    – Haxiel
    Nov 21 at 12:15












    It has nothing to do with rounding. Haxiel, good edit! @Haxiel
    – Michael Prokopec
    Nov 21 at 12:35





    It has nothing to do with rounding. Haxiel, good edit! @Haxiel
    – Michael Prokopec
    Nov 21 at 12:35













    up vote
    1
    down vote













    You should check the result of du without the | tail -1 | cut -1



    (ignoring the -h option which just add the k, M...)



    (based on http://man7.org/linux/man-pages/man1/du.1.html)



    -c will print the disk usage of all files plus a total. note that depending of your filesystem format disk usage of a file will be bigger than its real size)



    -bc will print the "real" size rather than the size its use on the disk.



    -bs will only print the total "real" size of each file/folder given to du. Since you dive du each file it will calculate the size of each *.conf file and your last line is the size of the last *.conf file you've given him.



    PS: you can probably do: du -bch *.conf rather than the grep on ls result.






    share|improve this answer
























      up vote
      1
      down vote













      You should check the result of du without the | tail -1 | cut -1



      (ignoring the -h option which just add the k, M...)



      (based on http://man7.org/linux/man-pages/man1/du.1.html)



      -c will print the disk usage of all files plus a total. note that depending of your filesystem format disk usage of a file will be bigger than its real size)



      -bc will print the "real" size rather than the size its use on the disk.



      -bs will only print the total "real" size of each file/folder given to du. Since you dive du each file it will calculate the size of each *.conf file and your last line is the size of the last *.conf file you've given him.



      PS: you can probably do: du -bch *.conf rather than the grep on ls result.






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        You should check the result of du without the | tail -1 | cut -1



        (ignoring the -h option which just add the k, M...)



        (based on http://man7.org/linux/man-pages/man1/du.1.html)



        -c will print the disk usage of all files plus a total. note that depending of your filesystem format disk usage of a file will be bigger than its real size)



        -bc will print the "real" size rather than the size its use on the disk.



        -bs will only print the total "real" size of each file/folder given to du. Since you dive du each file it will calculate the size of each *.conf file and your last line is the size of the last *.conf file you've given him.



        PS: you can probably do: du -bch *.conf rather than the grep on ls result.






        share|improve this answer












        You should check the result of du without the | tail -1 | cut -1



        (ignoring the -h option which just add the k, M...)



        (based on http://man7.org/linux/man-pages/man1/du.1.html)



        -c will print the disk usage of all files plus a total. note that depending of your filesystem format disk usage of a file will be bigger than its real size)



        -bc will print the "real" size rather than the size its use on the disk.



        -bs will only print the total "real" size of each file/folder given to du. Since you dive du each file it will calculate the size of each *.conf file and your last line is the size of the last *.conf file you've given him.



        PS: you can probably do: du -bch *.conf rather than the grep on ls result.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 10:52









        Bear'sBeard

        1113




        1113



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483173%2freally-weird-du-behaivour%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

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)