Linux – On linux, what does it mean when a directory has size 0 instead of 4096

directoryext4filesystemslinux

Here's a strange thing I haven't seen before — a directory whose size is reported by ls as 0 instead of 4096, and I can't create any files within it.

# ls -ld lib home
drwxr-xr-x.  2 root root    0 Feb  7 03:10 home  <-- it has zero size
dr-xr-xr-x. 11 root root 4096 Feb  4 09:28 lib
# touch home/foo
touch: cannot touch `home/foo': No such file or directory  <-- and I can't create files in it
# rm home
rm: cannot remove `home': Is a directory   <-- look, it really is a dir

So what does it mean for a directory to have size 0 instead of 4096?

Filesystem is ext4 on fedora core 14.

The output of mount is:

/dev/mapper/vg_dev-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/vda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

Output of du -s /home:

0   /home

Output of stat /home:

  File: `/home'
  Size: 0           Blocks: 0          IO Block: 1024   directory
Device: 15h/21d Inode: 34913       Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-02-07 03:45:46.188995765 -0800
Modify: 2011-02-07 03:11:59.980995019 -0800
Change: 2011-02-06 07:58:45.874995002 -0800

Best Answer

I'm guessing youre using autofs for your home directories.

A couple of different pseudo-filesystems will show up like this. Pseudo-filesystems being filesystems that dont really hold files. You'll notice /proc is also like this. Basically its because there is nothing in /home, no files, no anything. When you try to access it, autofs see's the request and tries to mount up the appropriate home directory as requested. With proc, those arent really files, theyre just representation of files as provided by the various drivers (and kernel) running on the system.

Edit: Shut off autofs and it'll show up like a normal directory.