LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Any fast way to know the total file size under a folder (https://www.linuxquestions.org/questions/linux-general-1/any-fast-way-to-know-the-total-file-size-under-a-folder-140208/)

gsbarry 01-29-2004 10:16 PM

Any fast way to know the total file size under a folder
 
I know that du command and give me the answer.

But, it is too slow for my usage because I need to check the folders which contains more than 1G of files.

Do any command that can give me the folder size instantly?

Bruce Hill 01-30-2004 01:13 AM

du -h gives it in human readable form in a nanosecond on my machine

jazernorth 01-30-2004 06:08 AM

Try:
---
du -h /home/<username>/

That will isolate it to that directory only.

JN

moses 01-30-2004 07:56 AM

Instantly is impossible. What du does is it stats the files to check their file size. Since you have a large number of files (I'm assuming), it's going to take a while to do that. Since you want this done, it has to be done either while you're paying attention or not. You could set up, for example, a cron job that checks the filesizes while you are busy doing other things and reports all of that info to a file called "Filesizes" under each filesystem (this is what we do at work), but the time is going to be spent either when you run du by hand or when it's run in the cron job. If you run a cron job, you can then just look in the Filesizes file to find what you need.

Bruce Hill 01-30-2004 08:09 AM

Quote:

Originally posted by moses
Instantly is impossible.
Please excuse my ignorance. It will lessen with time. I was thinking of df and not du. Thanks Moses - I appreciate your Linux wisdom.

xbeanx 01-30-2004 12:22 PM

du -hs

??

It may be a little faster cause it don't have to display all the filenames.

mikshaw 01-30-2004 01:31 PM

another option, if you just want a single directory (not recursive), is
ls -hs | head -1

gsbarry 01-30-2004 08:35 PM

I tried to compare this stuff between Windows and Linux.

In my Windows system, I have about 35000 files. It can give me the total filesize in about 15 seconds (right click all folders and click the Properties)

However, in Linux, for using "du -s", it takes more than 1 minutes to count only 7500 files.

Why is it so slow?
Actually, I only need a total, is there any faster way?

Well, instantly is impossible. But 15 seconds is better than 1 minute.

jsmarshall85 01-30-2004 09:20 PM

Quote:

Originally posted by gsbarry
In my Windows system, I have about 35000 files. It can give me the total filesize in about 15 seconds (right click all folders and click the Properties)
you can do the same thing in linux using kde or gnome although i'm not sure if it will be any faster, maybe linux just takes longer to parse the file system and come back with that info. the du -hs command works nicely though, but i'm not sure if you can pass a switch to it to look for files that are over a certain file size, but you can do that in kde or gnome too

moses 01-31-2004 12:02 AM

Is everything in one filesystem tree (i.e., does everything show up under one mount point)? If so, df -h /mountpoint will profide you with a reasonable facimile of what you want (as Chinaman meant to say).

What filesystem are you using for this (mostly out of curiosity).

Here's a faster way (in the root of the directory you wish to get the sum of all file sizes):
Code:

find . -printf %k"\n" | awk '{  sum += $1 } END { print sum }'
For some strange reason, it's faster than du. . . It takes maybe two seconds to run on 208050 files. . .
If you read the man pages, you could do some pretty cool stuff with this. . .

mikshaw 01-31-2004 08:50 AM

It may be faster because it doesn't have to print out a long list of files

moses 01-31-2004 02:05 PM

Code:

du -sh /path
doesn't print out a list of files either.

gsbarry 02-01-2004 10:35 PM

I have tried the commmnad

Code:

find . -printf %k"\n" | awk '{  sum += $1 } END { print sum }'
Actually, the speed is quite similar to du.

After some investigation, I found out that they main point is in the "updatedb" process.

Actually, every linux (i mean Redhat) will run the updatedb after bootup.
The updatedb will call the slocate which indexes the files so that searching of files is faster.

Yes, I fuond that the if this updatedb is being run (or du is run before), there will be an index database created. Thus, after that, every file searching or counting is very fast.

However, I have another issues that I needed to stop this updatedb process. Furthermore, for my requirment, everytime after reboot, I needed to get the folder size(not the whole filesystem, but only a subfolder that contains a lot of files). As a result, I still need to wait for a long time(about 2 mins) to count the folder size.......

Any help???

Megamieuwsel 02-01-2004 11:55 PM

Well , I tried to use what I learned in this thread , but I appear to be a little dense , it seems ;
How do you [i]exclude[/u] directories from it?
IE.- I want to know how much space is used on my mainpartition , but I have four other partitions mounted there as well : /hda8 , /hda9 / hda10 and hdc1.
I want these to be left out of the search.
I tried both the -x and the -X parameter but somehow I manage to get the syntax all wrong.

jsmarshall85 02-02-2004 08:24 PM

have you tried KDiskFree? it is a gui app on kde that shows partitions and mount points and how much space is on each one and how much is free.


All times are GMT -5. The time now is 09:30 PM.