if I do cd /usr ; ls -lF ,
the sizes of the directories are 1024 , I guess this is related to
block or fragment size.
with df /folder, i get the number of blocks for the whole filesystem
which is not very significative for me.
with du /path/to/folder, i get a listing.
may be i ll have to check in specific options in the man.
can you help me
thanks.
du -sk /path/to/directory
--
Chris "hehehe... he said folder" Watkins
if you use du -sxk it will only give you the total size instead of
giving all of the subdirectory sizes also.
That's what the "-s" option does, I thought.
I know "-k" gives the total, in 1024 byte blocks.
I'll have to look and see what "-x" does, next week.
I've just always used "du -sk /directory", myself, with the output being
the overall total of anything under that directory. It doesn't give a
total for each subdir, it just adds each to the grand total.
--
Chris
Sorry, you are correct, the x sets it so that it only gathers totals
from the same device, instead of all the subs underneath that are
separate mount points, I'm just slightly confused, you know you use
something for so long and dont even remeber why :-)
I know how that goes. There are several "habitual" commands I use, that
I probably couldn't tell you what each option does, without looking.
I only remembered the -s and -k to du, because that's a far more recent
addition to my arsenal. So many command line options... so little time :-)
--
Chris
Of course. :-)
du -sk /path/to/dir
gives space usage summary for given dir.
du -sk /path/to/dir/*/
gives identical summary for each subdirectory.
For a more exotic, but potentially more flexible, method:
find /path/to/dir -ls | awk '{sum+=$7};END{print sum}'
The last command can be tailored to you needs. ;-)
Need just files modified more than a week ago?
find /path/to/dir -mtime +7 -ls | awk '{sum+=$7};END{print sum}'
Only tar.gz files?
find /path/to/dir -name '*.tar.gz' -ls | awk '{sum+=$7};END{print sum}'
man find gives you all options available.
Enjoy! :-)
Umberto
Last consideration.
If hard links are involved, space reported is bigger, because linked
files are counted twice or multiple times, depending on number of links.
But, wait, I have just now a wonderful idea to solve that as well. :-)
I will post that when I've worked on that. I must first switch to my
FreeBSD partition, check if it works, then I will post it if it works...
Of course. :-)
I'm back. I've already tried my idea on FreeBSD.
First of all, I've discovered that FreeBSD is ahead on the hard links
issue and their du already counts hard links just once. Good news.
Then I've refined that find|awk better.
I've used $2 field, number of 512-blocks allocated, which is more
accurate than $7, filesize. Then I've exploited the $4 field,
number of hard links, to divide by number of hard links, so that
space is attributed as a fraction to each link, except for
directories because find command does not list .. entries.
This is the result:
# df -k /usr
1948168
# du -sk /usr
1948168
Let's try the first version which doesn't account for links:
# find /usr -ls | awk '{sum+=$2};END{printf "%d\n",sum/2}'
1979164
And now the corrected one (backslash used to wrap to the other line):
# find /usr -ls | \
awk '{(if($3~/\<d/)sum+=$2;else sum+=$2/$4;END{printf "%d\n",sum/2}'
1948167
Success! Just a small rounding error due to floating point arithmetic.
I miss only the test on major platforms, like HP-UX, Solaris, AIX.
I have to check that "~/\<d/" is supported. It may be a gawk extension.
I've also discovered that FreeBSD filesystem caching is not so bad. Apart
from the very first time, following executions were quite fast. :-)
Umberto
Done tests.
For awk, ~/d.*/ works nicely.
On HP-UX, find -ls option is not present.
Workaround is (\ to wrap...):
find DIR -print | xargs ls -ladis | \
awk '{(if($3~/d.*/)sum+=$2;else sum+=$2/$4;END{printf "%d\n",sum/2}'
xargs avoids plenty of ls executions...
On Sun Solaris and AIX, -ls is corrected to Kb units already.
No need to divide sum by two... (again \ to wrap):
find DIR -ls | \
awk '{(if($3~/d.*/)sum+=$2;else sum+=$2/$4;END{printf "%d\n",sum}'
HP-UX workaround works on Sun and AIX too.
On AIX blocks are 1K, so no need to divide sum by two.
Umberto