tags:

views:

43

answers:

1

Possible Duplicate:
When running ls -l, why does the filesize on a directory not match the output of du?

Hi. I'm interesting in information what show me output ls -la in linux. So, default size is 4K. But if there are a lot of files, maybe with zero size, such as PHP sessions =), the size != 4K. What showing me ls -la? And after, when i clean this folder i see tha last max size.

A: 

ls -al will give you the space taken up by the directory itself, not the files within it.

As such, it has a minimum size. When a directory is created, it's given this much space to store file information which is a set number of bytes per file (let's say 64 bytes thought the number could be different).

If the initial size was 4K, that would allow up to 64 files. Once you put more than 64 files into the directory, it would have to be expanded.


As for your comment:

The reason why it may not get smaller when you delete all the files in it is because there's usually no real advantage. It's just left at the same size so that it doesn't have to be expanded again next time you put a bucketload of files in there (it tends to assume that past behaviour is an indicator of future behaviour).

If you want to reduce the space taken, there's an old trick for doing that. To reduce the size of /tmp/qq, create a brand new /tmp/qq2, copy all the files across (after deleting those you don't need), then simply rename /tmp/qq to /tmp/qq3 and /tmp/qq2 to /tmp/qq. Voila! Oh yeah, eventually delete /tmp/qq2.

paxdiablo
But why, when i clean the directory, the size of ls are not changed?rm -rf *
Bkmz
Ok. Does Folder using this space? I find the folder with 684M))And how i can decrease the size of it?
Bkmz
@Bkmz, see my update for the trick used to do that. There may be other ways to do it depending on the filesystem used but that's basically the way we did it in the old days (and it still works).
paxdiablo
Actually are you sure that 684M is the size of the _directory_? Even with a directory entry size of 256 bytes, that would be 2.8 million files which seems a little excessive (although not impossible). Maybe the 684M is the size of the files within the directory.
paxdiablo