LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-29-2004, 10:16 PM   #1
gsbarry
Member
 
Registered: Jan 2003
Posts: 42

Rep: Reputation: 15
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?
 
Old 01-30-2004, 01:13 AM   #2
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: Tupelo, MS
Distribution: Gentoo
Posts: 6,926

Rep: Reputation: 124Reputation: 124
du -h gives it in human readable form in a nanosecond on my machine
 
Old 01-30-2004, 06:08 AM   #3
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
Try:
---
du -h /home/<username>/

That will isolate it to that directory only.

JN
 
Old 01-30-2004, 07:56 AM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
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.
 
Old 01-30-2004, 08:09 AM   #5
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: Tupelo, MS
Distribution: Gentoo
Posts: 6,926

Rep: Reputation: 124Reputation: 124
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.
 
Old 01-30-2004, 12:22 PM   #6
xbeanx
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Rep: Reputation: 0
du -hs

??

It may be a little faster cause it don't have to display all the filenames.
 
Old 01-30-2004, 01:31 PM   #7
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
another option, if you just want a single directory (not recursive), is
ls -hs | head -1
 
Old 01-30-2004, 08:35 PM   #8
gsbarry
Member
 
Registered: Jan 2003
Posts: 42

Original Poster
Rep: Reputation: 15
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.
 
Old 01-30-2004, 09:20 PM   #9
jsmarshall85
Member
 
Registered: Aug 2003
Posts: 386

Rep: Reputation: 30
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
 
Old 01-31-2004, 12:02 AM   #10
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
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. . .
 
Old 01-31-2004, 08:50 AM   #11
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
It may be faster because it doesn't have to print out a long list of files
 
Old 01-31-2004, 02:05 PM   #12
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
Code:
du -sh /path
doesn't print out a list of files either.
 
Old 02-01-2004, 10:35 PM   #13
gsbarry
Member
 
Registered: Jan 2003
Posts: 42

Original Poster
Rep: Reputation: 15
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???
 
Old 02-01-2004, 11:55 PM   #14
Megamieuwsel
Member
 
Registered: Sep 2002
Location: Haarlem , the Netherlands
Distribution: VectorLinux SOHO 5.1
Posts: 465

Rep: Reputation: 35
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.
 
Old 02-02-2004, 08:24 PM   #15
jsmarshall85
Member
 
Registered: Aug 2003
Posts: 386

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Folder Max Size and Limiting SSH access to home folder. Mefistofeles Linux - General 4 11-26-2005 02:09 PM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 02:26 AM
Total File Size meshcurrent Linux - General 1 05-17-2004 02:09 PM
Command to find total file size satimis Linux - Newbie 1 01-22-2004 11:19 AM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 03:47 PM


All times are GMT -5. The time now is 12:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration