31

I know these folders each have >80gb of files. Yet, they only show 4.0K in ls -lah? How can I have ls show size including the contents?

[root@aapsan01 aapxen01]# ls -lah
total 48K
drwxrwxrwx  6 root root 4.0K Sep 29 03:45 .
drwxrwxrwx 15 root root 4.0K Sep 27 09:15 ..
drwxr-xr-x  2 root root 4.0K Sep 29 03:45 aapxen01.0
drwxr-xr-x  2 root root 4.0K Sep 28 12:10 aapxen01.1
drwxr-xr-x  2 root root 4.0K Sep 27 09:21 aapxen01.2
drwxr-xr-x  2 root root 4.0K Sep 27 09:21 aapxen01.3

migrated from stackoverflow.com Sep 29 '10 at 13:36

This question came from our site for professional and enthusiast programmers.

35

du --max-depth=1 -h should show how much space the folders use

  • That's what I want. Thanks. Too bad they couldn't make an ls switch to provide this info. O well. – Flotsam N. Jetsam Sep 29 '10 at 13:39
  • I find that one pretty handy, so usually have it as an alias on my system like du-dir or something like that. – dtlussier Sep 29 '10 at 14:26
  • 1
    Actually adding --max-depth=1 is kind of weird choice, because then sub-subfolders (and files inside those) are not counted at all. From question it's not clear whether that was wanted or not. – Olli Mar 15 '11 at 17:46
  • @Olli Subfolders are counted, but not displayed. – Bernhard Nov 15 '12 at 6:57
  • Also equivalent to du -d 1 -h – checksum Nov 26 '13 at 8:02
13

Using the command du:

du -sh .

Note that this takes some time, because it has to scan the directory contents.

6

du -sh

where s displays a summary of the directory size.
h human readable format

Example:

[root@smsc tmp]# du -sh
219M    .
3

ls shows the size of the directory entry, not of the directory contents. The directory itself is basically a list of all file names contained in the directory, and thus quite small.

For getting the combined size of a directory and its contents, use du.

2
$ du -sm * | sort -n | tail -n 20
6       persilleriet
10      reading-material
22      Desktop
24      android
24      workspace
28      Dropbox
35      skole
36      2011v
38      fpsu
42      archives
46      prosj
54      2011erm
54      books
64      svn
99      reference
227     tmp
311     muz
331     images
370     src
663     Downloads
1

Use 'du'. Further explanation

1

To show the size of /var, use:

du -sh /var

To show the size of contents of /var, use:

du -sh /var/*

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.