14

Running du -shc * in the top directory gives 110G for a particular folder, whereas running the same command inside that folder gives a total size of 11G. How is that possible?

Platform Details: OS: CentOS 6.6 x86_64 Drive type: solid-state Volume type: RAID 6 array RAID Controller: LSI MegaRAID SAS Filesystem: ext3

1 Answer 1

9

Most probably you have hidden files in the folder. The point is that glob * selects only files and folders that do not start with .. So, if they do they are not passed to du command. On the other hand from top directory you get size of the directory as a whole, including dot files.

To match all files in given folder, including hidden ones try (with bash)

du -shc -- {.[!.],..?,}*

or set option dotglob so that * matches hidden files too:

shopt -s dotglob
du -shc -- *
4
  • 1
    Boy, am I embarrassed. I didn't think of that. I wish there were a simpler shell syntax for including hidden files in the expansion. Especially with commands like du, where you usually want to see everything in the folder. Thanks.
    – orodbhen
    Commented Jul 23, 2015 at 22:23
  • @orodbhen This glob is a little bit nerdy to take care of any "unusual" possibilities like files which start from two dots ..abc or which start from hyphen -abc. Most of the times you could just do du -shc * .??* or in shorter form du -shc {.??,}*. You cannot get rid of ? to not take parent directory .. into account. You can also set dotglob option in bash, so that it includes hidden files by default (I will add that to the answer).
    – jimmij
    Commented Jul 23, 2015 at 22:30
  • @orodbhen In zsh: *(D) (or make the inclusion of dot files the default with setopt glob_dots). Commented Jul 23, 2015 at 23:01
  • Been using Linux command line for 12 years, never even heard of the shopt command!
    – Dave
    Commented Jun 13, 2016 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .