Sunday, June 29, 2014

Unix Shell: File Time

1. ctime, mtime, atime
atime: last access time.
mtime: last modification time.
ctime: last change time.

2. Get different times of file:
terminal:
command stat can be used to list 3 different times of a given file.
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ stat test1  
  File: ‘test1’  
  Size: 0         Blocks: 0     IO Block: 4096  regular empty file  
 Device: 801h/2049d    Inode: 134252   Links: 1  
 Access: (0664/-rw-rw-r--) Uid: ( 1000/aubinxia)  Gid: ( 1000/aubinxia)  
 Access: 2014-06-29 15:22:47.468391015 -0400  
 Modify: 2014-06-29 15:22:47.468391015 -0400  
 Change: 2014-06-29 15:22:47.468391015 -0400  
  Birth: -  
=========================================
command ls can also be used to list 3 different times of a given file.
"ls -l " will give the last modification time
"ls -u" will give the last access time
"ls -c " will give the last change time
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -l test2  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 15:22 test2  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test2  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 15:22 test2  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lc test2  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 15:22 test2  

3. Last access time
The last time the file get read "on disk".
1) List the last access time of test3, which is 16:21
2) After running command "cat" to read test3, the access time get updated
3) List the last access time, it already get changed to 16:28
4) Running command "cat" to read test3 again. But when you run cat the 2nd time, the last access time doesn't get changed at all, the reason is probably unix has buffered the file content in memory, and it doesn't go to file system to access the file on disk.
5) List the last access time, it doesn't get changed.
6) Then we add "Hello world" to the tail of test3,
7) List the last access time, but change on content doesn't change the "last access time".
8) Next we run "cat" command again to read test3, since test3's content get changed, so unix has to go to disk to access test3, then last access time get updated.
9) List the last access time, it get updated.

 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test3  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 16:21 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ cat test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test3  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 16:28 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ cat test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test3  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 16:28 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ echo "Hello world!" >> test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test3  
 -rw-rw-r-- 1 aubinxia aubinxia 13 Jun 29 16:28 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ cat test3  
 Hello world!  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lu test3  
 -rw-rw-r-- 1 aubinxia aubinxia 13 Jun 29 16:29 test3  

4. Last change time
The time when file's status or content get changed.
terminal:
1) List the last change time of test3: 16:29
2) change the file status(permission)
3) List the last change time of test3: 16:36, meaning that changing file status could change the "last change time"
4) Add the new string to test3 file
5) List the last change time of test3: 16:37, meaning that changing file content could change the "last change time"
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lc test3  
 -rw-rw-r-- 1 aubinxia aubinxia 13 Jun 29 16:29 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ chmod +x test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lc test3  
 -rwxrwxr-x 1 aubinxia aubinxia 13 Jun 29 16:36 test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ echo "Hello world!" >> test3  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lc test3  
 -rwxrwxr-x 1 aubinxia aubinxia 26 Jun 29 16:37 test3  

5. Last Modification time:
The time when file's content get changed.
1) List the last modification time of test4: 16:21
2) change the file's status(permission)
3) List the last modification time of test4: 16:21, meaning that changing file status doesn't change the last modification time.
4) Add "Hello world!" to the file test4
5) List the modification time of test4: 16:40, meaning that changing file content could change the last modification time.
terminal:
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -l test4  
 -rw-rw-r-- 1 aubinxia aubinxia 0 Jun 29 16:21 test4  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ chmod +x test4  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -l test4  
 -rwxrwxr-x 1 aubinxia aubinxia 0 Jun 29 16:21 test4  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ echo "Hello world!" >> test4  
 aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -l test4  
 -rwxrwxr-x 1 aubinxia aubinxia 13 Jun 29 16:40 test4  

No comments:

Post a Comment