1

How can I find only the catalogs and sort them by the size (human-readable).

I tried with

find -type d | xargs du -h | sort -rn

But something goes wrong. And all the time its sorted by the numbers. So it doesn't see the difference between K, M etc.

6
  • Do you want it to be recursive, or list per root directory? – Runium Jan 10 '16 at 20:28
  • list per root directory. – Elizz Jan 10 '16 at 20:34
  • Then --max-depth=1 is a start when it comes to du. As in: skip find and do du --max-depth=1 -h . | sort -hr (If your tools support the options.) Is that what you are looking for? – Runium Jan 10 '16 at 20:47
  • Yeah! Thanks a lot! May ask u also why there is a dot ? W – Elizz Jan 10 '16 at 21:02
  • It is the target directory. Added an answer. – Runium Jan 10 '16 at 21:11
1

You could (perhaps) use:

du --max-depth=1 -h some_target_directory | sort -hr

given the version of the tools has the options available.

To skip the total; something like:

du --max-depth=1 -h some_target_directory | sort -hr | tail -n +2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.