29

I'm using zfs on my FreeBSD 9.0 x64 and pretty happy with it, but I find it hard to count directory real, not compressed, size.

Surely I can walk over the directory and count every file size with ls, but I'd expect some extra key for du for that purpose.

So, how can I tell the directory size for dir placed on zfs with compression on?

Thamk you in advance for the advice, I simple can't rememeber there is no such a 'simple' way, without 'find ./ -type d -exec ls -l '{}' \; | awk ...'!

2

3 Answers 3

37

Use the du with its -A flag:

root@pg78:/usr/local/pgsql/data/base/218204 # du -A -h 221350.219
1.0G    221350.219
root@pg78:/usr/local/pgsql/data/base/218204 # du -h 221350.219
501M    221350.219

Very handy. It even works with -d for recursive goodness:

root@pg78:/usr/local/pgsql/data/base # du -h -c -d0 .
387G    .
387G    total
root@pg78:/usr/local/pgsql/data/base # du  -A -h -c -d0 .
518G    .
518G    total
4
  • 1
    Really good solution! And the best it is there "right from the box"!
    – Alexander
    Commented Oct 4, 2012 at 6:38
  • 24
    Just a note, if your version of du doesn't have the -A option, -A is for "apparent size", which is available via --apparent-size. Ubuntu 16.04 / du 8.25 doesn't seem to have -A, so it seems like someone else might run into that issue. Commented May 16, 2017 at 14:16
  • 1
    Jim is right. It is -a or --apparent-size. At least on Ubuntu 22.04.1 LTS Commented Dec 5, 2022 at 12:47
  • Jim is wrong. It is not -a or --apparent-size for FreeBSD's du, which is what this question is about (very first word in the title, even). More troubling, using -A with FreeBSD's du gives results that are smaller than what zfs list reports, so clearly this is not correct. GNU's du also gives a smaller (although different) size to zfs list.
    – anahata
    Commented Jun 15, 2023 at 0:18
16

You could install the GNU version of du(1):

cd /usr/ports/sysutils/coreutils && make install clean

Then you can use the --apparent-size flag:

/space# zfs create space/comptest
/space# zfs set compression=on space/comptest
/space# dd if=/dev/zero of=/space/comptest/zerofile bs=1M count=40
/space/comptest# gdu
2K      .
/space/comptest# gdu --apparent-size
40961K  .
3
  • 6
    There is NO reason to use a port for this. Use the base OS du with its -A flag.
    – Sean
    Commented Oct 4, 2012 at 0:05
  • 11
    This is useful for ZFS on Linux. GNU du doesn't have a -A option.
    – jakar
    Commented May 31, 2014 at 6:55
  • 4
    ZFS on Linux's du has --apparent-size from the comment on the accepted solution here: serverfault.com/a/434655/145009 Commented Dec 13, 2017 at 21:15
2

try to use zpool command :

zpool list
NAME      SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
storage  8.93T  6.59T  2.34T         -    60%    73%  2.13x  ONLINE  -

but df -sh shows resulting (not deduplicated size)

df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
storage        zfs        16T   14T  1.9T  89% /storage

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .