4

I've been trying to establish a way to retrieve the folder size of around 5000 folders, which are contained in a folder with a total of around 15000 folders.

So for example:

Parent folder
   -- SubFolder
   -- SubFolder2
   -- SubFolder3
   -- SubFolder4

I only want to retrieve the folder size of SubFolder3 and SubFolder4 ... on a small scale this is of course trivial. When we're dealing with thousands it becomes a little more complex.

I had hoped that using something like unixkit-tiny with:

du -k --max-depth=1 < folderlist.txt | > foldersizes.txt

Would work, but that command sadly ignores the input - although the output works just fine.

Oliver Salzburg
  • 87,539
  • 63
  • 263
  • 308

1 Answers1

3

If you're going to use unix tools:

xargs -L1 du -k --max-depth=1 <folderlist.txt >foldersizes.txt

Remember, unix commands tend to do one job. The job of du is to total file sizes. The job of xargs is to read a list of lines from a file.

By the way, did you really mean --max-depth=1, i.e., show the size of each subdirectory of the directories listed in folderlist.txt but don't detail their subdirectories? More commonly used options are -s (show the size of the listed directories, don't detail their subdirectories) and -S (don't include the size of subdirectories).

  • That's perfect. My unix command line is a little shaky so thanks for the clarification - very very helpful. You were also spot on with -s over --max-depth. Really hope this helps other folk in the future as I bashed (no pun intended) my head against this for about an hour earlier :) – suitedupgeek Jul 28 '10 at 20:09