Are files defined by their content blocks, inodes, both, or filenames, or something else? Fundamentially, what is the definition of a file?


two hard links can share the same inode and thus content blocks, but they have different filenames. Are they considered the same file or different files?

Are there some files which have different inodes, but the same content block? Are they considered the same file?



2 Answers 2


I'm assuming we're discussing "regular" files, not device files or unix-domain sockets or something not-so-regular like that.

I would say that files have names, metadata, and data.

This corresponds directly to filenames, inodes and blocks.

I believe that your two, hard-linked filenames are just two names for a single file.

I don't believe that under Unix or Linux or *BSD, you can have two inodes referencing the same data blocks without some kind of very unusual intervention. An suid program could potentially open a disk's device file, and manipulate two inodes to point to the same data blocks, but I sincerely doubt that situation could arise organically.

  • and fsck would fix it if it happened.
    – hildred
    May 6, 2015 at 23:58
  • Thanks. What about "device files or unix-domain sockets or something not-so-regular like that"?
    – Tim
    May 7, 2015 at 0:46
  • @Tim - the not-regular-files don't really have data blocks. Maybe named pipes do, but the not-regular-files all need the kernel to do a lot more on each read or write. Unix-domain sockets need to have a user process on the other end. Device files reference a whole disk, or a disk partition. You can think of them as either "all of the data blocks" or "don't really have data blocks". It doesn't really make sense to think of "data blocks" in the context of not-regular-files.
    – user732
    May 7, 2015 at 1:00
  • Do not-regular-files have inodes?
    – Tim
    May 7, 2015 at 1:06
  • @Tim - yes, all special files have inodes. That's how ls can show you /dev/sda1 or /tmp/.X11-unix/X0. If you do man 2 stat you can see the st_mode field of struct stat, and the C-language macros to decide what files types. An inode (on-disk data) example is in /usr/include/ext2fs/ext2_fs.h on my machine. struct ext2_inode has an i_mode member that has a particular bit set for each of the special file types.
    – user732
    May 7, 2015 at 2:22

Filenames are used to lookup inodes. Nothing else. Inodes are the main point to reference a file. Afile may not have any data blocks at all if it is zero size or if it is small enough to fit in the blocklist portion of the inode and the filesystem has that optimization. if there are two hard links pointing at one inode it is still one file, it just has more than one name. This allows you to do such things as to rename and delete open files. This makes it much easier to upgrade software on a running system unlike windows where the primary identifier is the filename and you have to reboot after every upgrade to replace files in use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.