2

In general on a UNIX-like system (Linux, AIX) the following can list file/directory sizes in MByte, even if the filename is starting with a "-":

du -sm -- * 2>/dev/null | sort -nr | head -25

But this doesn't list the directories/files that are "hidden", so starting with a ".".
How can I do that in general?

This solution isn't good:

du -sm -- .* 2>/dev/null | sort -nr | head -25

Because it counts ".." too, and that could be slow..

2
  • The problem is du has -a flag but you can summerize and list all (-a) in the same command. So use du -a 2>/dev/null | sort -nr | head -25 and use awk to convert the bytes to Mbytes Mar 30 '15 at 5:24
  • For me, "-a" lists subdirectories too, that isn't needed but thanks! Mar 30 '15 at 5:33
1

You can use

du -mad 1

for your purpose. Like @Miline suggested, -a flag will show both files and directory. Using -d 1 will limit the output into only one layer of subdirectory(depth<=1), i.e. files of current folder and subfolder(without detail in content).

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.