4
  1. In Linux, the information about a file or directory is stored in its inode. I was wondering what is the data structure for information about a file or directory in Windows 7?
  2. How to get the information about a file or directory in Linux and in Windows 7, in terminal and command line window?
  3. Is the owner of a file or directory always its creator? Will it be able to change?
  4. Is there a creation timestamp for a file in Linux and in Windows 7? How to get it?

Thanks and regards!

2 Answers 2

2

In Linux, the information about a file or directory is stored in its inode. I was wondering what is the data structure for information about a file or directory in Windows 7?

In both operating systems, this depends on which file system is being used.

Windows uses NTFS by default, which has "attribute lists" in its Master File Table. There is some documentation in Wikipedia, at NTFS.com and Linux NTFS.

The older FAT32 filesystem (still used often in removable drives) is much simpler, and keeps everything in a single file allocation table.

How to get the information about a file or directory in Linux and in Windows 7, in terminal and command line window?

In Linux, use the stat command.

In Windows PowerShell, use System.Io.FileInfo.

In Windows cmd.exe, you have to use either external tools or mess with dir.

Is the owner of a file or directory always its creator? Will it be able to change?

  • On Windows NT (including XP, 2003, Vista, 7, and future versions), newly created objects1 are owned by their creator, unless someone else takes ownership. (Administrators can do this by using SeTakeOwnership privilege; non-Administrators can take ownership if the object's ACL allows it.)

    • On server editions of Windows NT, Administrators can assign object ownership to another user. Consumer editions (such as Windows XP or 7) only allow taking ownership to yourself.

    • In Windows 2000 and earlier versions, if the creator is member of the Administrators group, the objects he creates will be owned by Administrators, not the user. This changed in Windows XP, where the user will always own objects he creates.

    • The FAT filesystems do not support file ownership.

  • All[citation needed] Unix systems use the file's creator as its owner.

    • root can use chown to change the owner.

Is there a creation timestamp for a file in Linux and in Windows 7? How to get it?

  • In Windows, both FAT32 and NTFS store a creation timestamp. In cmd.exe, dir /tc will show it.

  • FreeBSD's UFS2 stores the creation time as st_birthtime.

  • On Linux, creation times are supported by some filesystems (ntfs, possibly ext4), but not yet by the OS itself. (The stat command already shows birth times, if supported by the syscall of same name.)

Note: On Windows and FreeBSD, the creation time is easy to change.


1 This applies to many other types of Windows NT objects, not limited to files. Examples: named pipes, Registry keys, processes, services, desktops, devices, mutexes...

5
  • Correction: in Unix systems owner can change ownership with chown too.
    – ulidtko
    Feb 6, 2011 at 15:25
  • @ulidtko: Incorrect. See Linux ("Only a privileged process (Linux: one with the CAP_CHOWN capability) may change the owner of a file."), BSD ("...the change owner capability is restricted to the super-user")... Feb 6, 2011 at 15:32
  • 1
    @ulidtko: ...and Unix 7th Edition ("Only the super-user may execute this call, because if users were able to give files away, they could defeat the (nonexistent) file-space accounting procedures." – Windows follows the same reasoning). // The group, however, can be changed – if the user is a member of the target group. Feb 6, 2011 at 15:33
  • True, I was wrong.
    – ulidtko
    Feb 6, 2011 at 15:35
  • 2
    @ulidtko: And this SU question: superuser.com/questions/164526/…
    – Hello71
    Feb 6, 2011 at 15:41
3

I don't know about Windows 7, but will try to answer Linux parts.

  1. True, except for file name.
  2. The stat(1) utility can get all the information about an inode. Accompanying syscall, stat(2) can be used in your programs.
  3. No, the owner of a file or directory can be changed in any moment, see chown(8). See also sticky bit.
  4. No, in Linux the creation timestamp is not stored. See the stat(2) syscall, specifically the struct stat definition. Last access time (st_atimespec), modification time (st_mtimespec) and inode data modification time (st_ctimespec) are available.
6
  • Re #4 - it can be stored, it's just not accessible through stat(2) (yet). Feb 6, 2011 at 15:23
  • Does "(2)" in "stat(2)" mean the category in manpage of "stat(2)"?
    – Tim
    Feb 6, 2011 at 15:27
  • @grawity Though this is non-standard (non-POSIX) feature and very unlikely will be available on other systems. Use at you own courage.
    – ulidtko
    Feb 6, 2011 at 15:29
  • @Tim yes. [placeholder]
    – ulidtko
    Feb 6, 2011 at 15:30
  • @ulidtko: FreeBSD, OS X and NetBSD already have (varying) implementations of st_birthtime. I heard Solaris does too. Feb 6, 2011 at 15:38

You must log in to answer this question.

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