du -csh /
The above will take huge amount of time to calculate,is there a way to see the less accurate result with less overhead?
What I want to know is the total size under a specific directory.
As far as a more optimized version
du, I am not aware of one. The things that come to mind are:
stat -c '%h') - 2.
Out of all these, the quota and dedicated partition options are probably the easiest and most efficient.
The problem is that 'du' has to enumerate every object in the sub-tree. This is a metadata intensive operation, and takes a while for most Linux filesystems. Some filesystems, NTFS and Novell's NSS come to mind, have the ability to keep track of directory sizes like this in the metadata which makes this operation vastly faster. Generally, if your file-system supports directory quotas of some kind, it has to keep track of this data internally for enforcement, every size-change is replicated up the directory-tree to the quota-point (NTFS) or every directory (NSS) when it happens, so getting a directory-tree size is very fast.
Unfortunately, there isn't a way to make du run faster, just work-arounds.
du -h --max-depth=1
Gives you the sizes in human KB/MB/GB format from your current working directory.
With the standard tools you have to get the size of every file in the directory each time you want to know the total size. A possibly more efficient way to do it would be to have a "directory size monitor", which keeps track of the current size of the directory. There is no such thing (that I know of), but you could implement one with
inotify. Possibly not with bash (and
inotify-tools), but you could probably use python and pyinotify, for example.
Also, consider the -x option on du -- "one file system" if your doing
du -xh / --max-depth=1
You'll only see the disk usage summary on your root partition, and it won't try to add up /proc, /sys, /dev, and so on...
No. Could you periodically do a du piped to a text file, in a cron job set to run overnight, so you've got not quite current data immediately available?
Note that measuring the disk space used by a folder containing a large no of files under Windows similarly takes some time.
if you only want disk usage for root file system, then
df -h /
df -h will do the trick
df -kh /
this will show you the amout of disk space used and available.
extra text since a short, concise answer isn't enough for serverfault to think I am human.
To find the space under just that directory, list it instead of
/. To find the space under directories
bar, list both:
du -csh foo bar
You should use dnotify to calculate the disk usage if the filesystem is not changed often.