Hi ,
this is what i have read in a book
Because Linux directories do not shrink automatically, removing a file from a directory does not shrink the directory, even though it frees up space on the disk.remove unused space and make a directory smaller, you must copy or move all the files to a new directory and remove the original directory.
maxwell lol
There are two different ways to think of the size of a directory.One is the size based on the contents of the directory. du shows this.
The second is the size of the "file" that contains the inode information of the files inside the directory. Don't get these confused.The inode information gives the name of the files inside the directory.
If you do a ls -ld dirname, ls will show you the size of this file.
For instance:
drwxr-xr-x 2 root root 36864 2008-10-13 06:59 bin
drwxr-xr-x 2 root root 4096 2008-04-24 02:09 games
drwxr-xr-x 9 root root 4096 2008-10-06 06:32 include
drwxr-xr-x 120 root root 53248 2008-10-06 06:32 lib
drwxr-xr-x 3 root root 4096 2008-06-13 06:42 lib32
drwxr-xr-x 10 root root 4096 2008-04-24 02:04 local
Now du shows (in 1k blocks)
147528 bin
40 games
740 include
395440 lib
8 lib32
152 local
It is true that the size of the directory file grows as needed as you create more files. And when files are moved or deleted, the records in this file are marked "unused". So the file does not shrink in size.
But normally this difference is so small, it's not worth worrying about. In the above case, /usr/bin contains 147M, but the size of the bin file is 32K.
Trying to recover 8K of space on a 200GB disk is silly. But you are correct.
Rikishi42
Completely.
I have a directory in which sometimes 150.000+ files arrive, before they get filed to their proper directories.This dir reaches 3.6 MB at times. So far, the only way I've found to reduce
it, is to remove and recreate it each time my procedure has emptied it.
The Natural philosopher
Yes. that is correct on the file systems I have used. There is no 'garbage collection" on directories as such. Just the contents.It may not be correct on all filesystems tho, I dont know.
John hassler
Rikishi42 writes:
> I have a directory in which sometimes 150.000+ files arrive, before they
> get filed to their proper directories.
> This dir reaches 3.6 MB at times.
How large is the partition?
> So far, the only way I've found to reduce it, is to remove and recreate
> it each time my procedure has emptied it.
What do you gain by reducing it? It's just going to grow back to 3.6M next time you receive 150,000 files. Think of it as space pre-allocated for directory entries. You do realize that the slots get reused?
Rikshi42
>> I have a directory in which sometimes 150.000+ files arrive, before they
>> get filed to their proper directories.
>> This dir reaches 3.6 MB at times.
> How large is the partition?
The use of space was not really the point. Sorry, I should have explained that. Imagine how sluggish a dir with 150.000 files feels. The 'problem' is that when the directory is emptied, it stays just as slow.
>> So far, the only way I've found to reduce it, is to remove and recreate
>> it each time my procedure has emptied it.
> What do you gain by reducing it? It's just going to grow back to 3.6M next
> time you receive 150,000 files. Think of it as space pre-allocated for
> directory entries. You do realize that the slots get reused?
I gain speed, mostly.And all my file arrivals are not that big.
No comments:
Post a Comment