Operating System - Linux
1753403 Members
7614 Online
108792 Solutions
New Discussion

Re: How to see a file's create time, access time and modification time

 
SOLVED
Go to solution
senthil_kumar_1
Super Advisor

How to see a files create time , access time and modification time

Hi All,

 

How to see a files create time, access time and modification time?

 

What does access time and modification time mean?

 

 

5 REPLIES 5
Dennis Handly
Acclaimed Contributor

Re: How to see a file's create time, access time and modification time

>How to see a file's create time, access time and modification time?

 

Unix and Linux don't track creation time.

You can see the latter two with "ls -lu" and "ls -l".

>What does access time and modification time mean?

 

Modification means what you expect, the file was modified.

Access means the file was ether read or written.

H.Becker
Honored Contributor
Solution

Re: How to see a file's create time, access time and modification time

Have a look at  the fstat man page. There are three time fields st_atime, st_mtime and  st_ctime: time of last access, last modification and last status change. None of these holds the creation time/date.

Further the man page explains when which field is updated. With ls you can see these times. On Linux it just looks like this:
 
$ rm -f aFile
$ touch aFile
$ ls -lu --full aFile # shows atime
-rw-r--r-- 1 joe users 0 2012-02-25 16:42:05.616078588 +0100 aFile
$ ls -l  --full aFile # shows mtime
-rw-r--r-- 1 joe users 0 2012-02-25 16:42:05.616078588 +0100 aFile
$ ls -lc --full aFile # shows ctime
-rw-r--r-- 1 joe users 0 2012-02-25 16:42:05.616078588 +0100 aFile
$ echo >>aFile hello
$ ls -lu --full aFile # shows atime
-rw-r--r-- 1 joe users 6 2012-02-25 16:42:05.616078588 +0100 aFile
$ ls -l  --full aFile # shows mtime
-rw-r--r-- 1 joe users 6 2012-02-25 16:43:14.989031242 +0100 aFile
$ ls -lc --full aFile # shows ctime
-rw-r--r-- 1 joe users 6 2012-02-25 16:43:14.989031242 +0100 aFile
$ chmod o+w aFile 
$ ls -lu --full aFile # shows atime
-rw-r--rw- 1 joe users 6 2012-02-25 16:42:05.616078588 +0100 aFile
$ ls -l  --full aFile # shows mtime
-rw-r--rw- 1 joe users 6 2012-02-25 16:43:14.989031242 +0100 aFile
$ ls -lc --full aFile # shows ctime
-rw-r--rw- 1 joe users 6 2012-02-25 16:44:22.435327799 +0100 aFile
$ cat aFile 
hello
$ ls -lu --full aFile # shows atime
-rw-r--rw- 1 joe users 6 2012-02-25 16:45:18.901684610 +0100 aFile
$ ls -l  --full aFile # shows mtime
-rw-r--rw- 1 joe users 6 2012-02-25 16:43:14.989031242 +0100 aFile
$ ls -lc --full aFile # shows ctime
-rw-r--rw- 1 joe users 6 2012-02-25 16:44:22.435327799 +0100 aFile
$
 
As you can see, writing to the file with echo didn't change the access time.
abbasmohammed
Occasional Visitor

Re: How to see a file's create time, access time and modification time

Hi All,

 

We can see using "stat" command.

 

stat filename

 

it will show the requested things

Dennis Handly
Acclaimed Contributor

Re: How to see a file's create time, access time and modification time

>it will show the requested things

 

Except for creation time.

Ajin_1
Valued Contributor

Re: How to see a file's create time, access time and modification time

# stat /etc/passwd
  File: `/etc/passwd'
  Size: 7623            Blocks: 16         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 314330      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-11-25 12:55:42.000000000 +0300
Modify: 2014-10-24 07:27:51.000000000 +0300
Change: 2014-10-24 07:27:51.000000000 +0300

Thanks & Regards
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.