Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to get a list of the directories and their sizes in a list format like how you get when you do a ls -l.

The thing is that is there a one line command that can do this? I see others have long commands just to output this. That's just too long.

What command can do this or combination of commands that can be easily typed? du -h gives it, but it displays all of the sub-folders which is not what I want. just the current directories folders.

share|improve this question
    
+1 this had always bugged me! –  Mehrdad Feb 19 '13 at 16:55
add comment

1 Answer

up vote 9 down vote accepted

Try this

du -h --max-depth=1

Output

oliver@home:/usr$ sudo du -h --max-depth=1
24M     ./include
20M     ./sbin
228M    ./local
4.0K    ./src
520M    ./lib
8.0K    ./games
1.3G    ./share
255M    ./bin
2.4G    .

Alternative

If --max-depth=1 is a bit too long for your taste, you can also try using:

du -h -s *

This uses -s (--summarize) and will only print the size of the folder itself by default. By passing all elements in the current working directory (*), it produces similar output as --max-depth=1 would:

Output

oliver@cloud:/usr$ sudo du -h -s *
255M    bin
8.0K    games
24M     include
520M    lib
0       lib64
228M    local
20M     sbin
1.3G    share
4.0K    src

The difference is subtle. The former approach will display the total size of the current working directory and the total size of all folders that are contained in it... but only up to a depth of 1.

The latter approach will calculate the total size of all passed items individually. Thus, it includes the symlink lib64 in the output, but excludes the hidden items (whose name start with a dot). It also lacks the total size for the current working directory, as that was not passed as an argument.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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