Access time of a file

I thought that access time of a file is time when the file was run last time (or I read somewhere that it's time when system lookup the file -> but I'm not sure when it really is)

How is it exactly?

Thank you for help!

It's the time a process last accessed it to read/write contents.

i read somewhere the documentation for the c function stat, and describe what type of access changed the mod time.
im sure that tail (awk, head, and surely more) dont change it

2Broli: Well and what is the access time for then? I mean if behaviour of programs is different..

From the POSIX standards:

st_atime == atime
st_ctime == ctime
st_mtime == mtime

Plus if you search the forum for file time you will find a lot of good information.

Broli - the definitions of these have been fixed for years - different apps do not violate those definitions. Things that can change mtime are opening a file for write/append or a call to utime() (e.g., touch). chmod or chown changes ctime, and utime or opening a file for read changes the atime. These values are NOT part of the file, they are file metadata maintained by the filesystem, as accessed thru the kernel.

I made a simple script and copied the output:

file=example_1.sh;stat $file; cat $file >/dev/null; stat $file
  File: `example_1.sh'
  Size: 918             Blocks: 2          IO Block: 4096   regular file
Device: fh/15d  Inode: 2099578354  Links: 1
Access: (0744/-rwxr--r--)  Uid: (13654/vsetm7am)   Gid: (  200/ nofiles)
Access: 2008-09-02 21:47:11.000000000 +0200
Modify: 2008-09-02 21:47:11.000000000 +0200
Change: 2008-09-02 21:47:11.000000000 +0200
  File: `example_1.sh'
  Size: 918             Blocks: 2          IO Block: 4096   regular file
Device: fh/15d  Inode: 2099578354  Links: 1
Access: (0744/-rwxr--r--)  Uid: (13654/vsetm7am)   Gid: (  200/ nofiles)
Access: 2008-09-02 21:47:11.000000000 +0200
Modify: 2008-09-02 21:47:11.000000000 +0200
Change: 2008-09-02 21:47:11.000000000 +0200

How come that access time didn't change when data was accessed?

We would need to know the OS and how the file system was mounted. As one example: Sun's mount_ufs man page documents the noatime option:

Another example: the source files might be on cd-rom.

I am aware of some UNIX-like enviroments where st_atime is not updated after a read. Interix i.e. Microsoft SUA is one and I think Cygwin is another.

What happens if you touch the file using the touch(1) utility?

touch -a will modify the atime. touch access metadata like stat does. It doesn't open the file for read or write.

POSIX says that

In other words both filetimes are updated.

fpmurphy:

u-pl27:~/ZKOUSKOVE/TEZSI_PRIKLADY$ stat example_1.sh
  File: `example_1.sh'
  Size: 918             Blocks: 2          IO Block: 4096   regular file
Device: fh/15d  Inode: 2099578354  Links: 1
Access: (0744/-rwxr--r--)  Uid: (13654/vsetm7am)   Gid: (  200/ nofiles)
Access: 2008-09-02 21:47:11.000000000 +0200
Modify: 2008-09-02 21:47:11.000000000 +0200
Change: 2008-09-02 21:47:11.000000000 +0200
u-pl27:~/ZKOUSKOVE/TEZSI_PRIKLADY$ touch example_1.sh
u-pl27:~/ZKOUSKOVE/TEZSI_PRIKLADY$ stat example_1.sh
  File: `example_1.sh'
  Size: 918             Blocks: 2          IO Block: 4096   regular file
Device: fh/15d  Inode: 2099578354  Links: 1
Access: (0744/-rwxr--r--)  Uid: (13654/vsetm7am)   Gid: (  200/ nofiles)
Access: 2008-09-05 19:54:14.000000000 +0200
Modify: 2008-09-05 19:54:14.000000000 +0200
Change: 2008-09-05 19:54:14.000000000 +0200

MartyIX, are you on a Solaris 10 box with a ZFS filesystem?

I ask because the output of the stat utlity looks like that of Solaris and ZFS has an option to turn off atime updating.

@fpmurphy: uname command writes:

GNU/Linux 2.6.22-p4smp