On 03/12/2018 03:37 PM, Patrick O'Callaghan wrote: > On Tue, 2018-03-13 at 07:26 +1100, Stephen Morris wrote: >>> 'du' with no parameters recursively lists all the subdirectories and >>> their sizes, along with the grand total. When applied to my home >>> directory, I get over 30,000 lines of output. That's almost never what >>> I want. My usual call is 'du -hs'. >>> >>> poc >> >> Thanks Patrick, taking this a step further, it seems to me that the only >> parameter for du that, to me, provides the correct file size is -b as >> shown below. > > I think you have a misconception here. 'du' does not give file sizes, > it gives disk usage. A 1-byte file takes up at least 1 disk block, so > that's the size 'du' will give. I seem to remember that it also counts > indirect blocks and other housekeeping that corresponds to the file > without being included in the file's content, but I could be mistaken > (though I'm fairly sure early versions did do that). du (with no flags) gives disk usage. As Patrick says, a 1-byte file uses one disk block (which is generally 4KiB) and that's what du is reporting (after all, "du" means "disk usage"). The "-b" flag means "set the block size to 1 byte and show the apparent size", which is what "ls -l" would report (there may be differences between du and ls if sparse files are involved). Also, du walks down the entire current directory unless you give it arguments to tell it what to look at. Note that the arguments you pass it are interpreted by the _shell_, not "du" (even the man page says "PATTERN is a shell pattern (not a regular expression)"). This is a common confusion point with many people. Unless you enclose shell metacharacters in quotes (and dots and splats are metacharacters), the shell WILL interpret them--sometimes in ways you aren't expecting! By default, shell globbing does NOT expand filenames that start with a dot (to the shell, a dot means "current directory"). If you want to list JUST files/dirs that start with a dot, you can use "du [flags] \.* (so the shell interprets the dot as a dot, not "current directory"). Or you can tell the shell to expand files starting with a dot by using "shopt -s dotglob" (as Ed said). "shopt -u dotglob" will restore the default setting. ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@xxxxxxxxxxxxxx - - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 - - - - The Theory of Rapitivity: E=MC Hammer - - -- Glenn Marcus (via TopFive.com) - ---------------------------------------------------------------------- _______________________________________________ users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx