Today I came across this command.
I needed to find the size of a directory from inside a C Program.
While searching, found this... du
gives the size of a file OR all the files / folders inside a particular directory.
It is not actually the size of the directory, the size of a directory is always 4KB. What we need is the disk usage.
If you want to get the size of the folder foo in user readable form (KB, MB) : du -h foo
If you don't want the size of files inside the folder, but only the total size of the folder : du -s -h foo
You can print only the size in bytes : du -s foo | awk '{print $1}'
Still, I don't know how to get it from a C program. Any ideas?
Thursday, May 29, 2008
du (Linux CLI)
Subscribe to:
Post Comments (Atom)
1 comments:
It seems you are searching for
du -ch | grep total
or
du -sh
This link will of help to you:
http://www.codecoffee.com/tipsforlinux/articles/22.html
From programming perspective:
get all the files in the dir
do stat() on each file
accumulate the size
I hope this link comes to your help:
http://developer.novell.com/wiki/index.php/Programming_to_the_Linux_Filesystem
Post a Comment