Regarding unix access time

I want to know what access time is. Search the Internet, but get the same definition (reading changed). I know with alarm that we can change it. Can someone explain me more about this by the example of how it has changed. Also is there a way to create a file date / time in unix?

+7
linux unix
source share
4 answers

The stat(2) structure keeps track of the entire file date / time:

  struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system I/O */ blkcnt_t st_blocks; /* number of 512B blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ }; 

st_atime is access time updated by read(2) calls (and probably also when open(2) opens a file for reading) - it is NOT updated when files are read through mmap(2) . (This is why I assume open(2) will mark the access time.)

st_mtime - time to change data, either through write(2) , or truncate(2) or open(2) for writing. (Again, it is NOT updated when files are written via mmap(2) .)

st_ctime - metadata modification time: when any of the other data in the struct stat changes.

You can change timestamps on files using utime(2) :

  struct utimbuf { time_t actime; /* access time */ time_t modtime; /* modification time */ }; 

Note. You can change the access time change time and (data). You can set any of them at any time, but ctime will be set to the current time - because you changed the metadata for the file.

There is no creation time in this structure, so it is impossible to know when the file was created directly from the system.

If you really need to know the creation time, you can narrow it down to a range by looking at your backups - assuming that the file you are interested in has been copied along with its metadata.

+19
source share
  • last access: the time the file was last accessed. Modified using the mknod (2), utimes (2), and read (2) system calls.

  • Last Modified: The time the file was last modified. Changed using mknod (2), utimes (2) and records (2) system calls.

  • Last change: time of the last change in file status (change inode data). Changed chmod (2), chown (2), link (2), mknod (2), rename (2), unlink (2), utimes (2) and record (2) system calls.

    / li>
+13
source share

Contrary to the answer above, the creation date or actual date of birth is stored and can be accessed, see https://unix.stackexchange.com/a/50184/8250 (debugfs should be done in sudo)

+1
source share

The average time between requesting information stored in a particular component, such as hard output or RAM, and its delivery. In another word, the time between the read request and when the desired word appears. For example, 235,288 units / 13.82 transactions = 16.8 units per transaction.

-3
source share

All Articles