Really weird ```du``` behaivour

Clash 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?
shell-script shell size
add a comment |
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?
shell-script shell size
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
add a comment |
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?
shell-script shell size
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
shell-script shell size
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
add a comment |
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
add a comment |
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
I see and what do I do if I have to display du -hc inbytes?
– C. Cristi
Nov 21 at 10:55
du -bcwill show all of the file sizes and the grand total in bytes.
– Haxiel
Nov 21 at 10:59
I want the rounded size, withhcin 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
add a comment |
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.
add a comment |
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
I see and what do I do if I have to display du -hc inbytes?
– C. Cristi
Nov 21 at 10:55
du -bcwill show all of the file sizes and the grand total in bytes.
– Haxiel
Nov 21 at 10:59
I want the rounded size, withhcin 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
add a comment |
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
I see and what do I do if I have to display du -hc inbytes?
– C. Cristi
Nov 21 at 10:55
du -bcwill show all of the file sizes and the grand total in bytes.
– Haxiel
Nov 21 at 10:59
I want the rounded size, withhcin 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
add a comment |
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
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
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 inbytes?
– C. Cristi
Nov 21 at 10:55
du -bcwill show all of the file sizes and the grand total in bytes.
– Haxiel
Nov 21 at 10:59
I want the rounded size, withhcin 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
add a comment |
I see and what do I do if I have to display du -hc inbytes?
– C. Cristi
Nov 21 at 10:55
du -bcwill show all of the file sizes and the grand total in bytes.
– Haxiel
Nov 21 at 10:59
I want the rounded size, withhcin 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 21 at 10:52
Bear'sBeard
1113
1113
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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