I created a simple text file and checked its timestamps using stat
and here is the output:
stat Output before any python script
papagolf@Sierra ~/My Files/My Programs/Learning/Python % stat prac09_timestamp.txt
File: prac09_timestamp.txt
Size: 10 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 2485542 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/papagolf) Gid: ( 1001/papagolf)
Access: 2017-09-10 11:10:40.979845492 +0530
Modify: 2017-09-10 11:10:40.979845492 +0530
Change: 2017-09-10 11:10:40.979845492 +0530
Birth: -
Then I ran a python script that simply opens the file in read mode. I was expecting the time "Access" stamp to change but it didn't.
Python Script and output of stat after running it
papagolf@Sierra ~/My Files/My Programs/Learning/Python % cat python prac09_timestamp.py
cat: python: No such file or directory
a = open("prac09_timestamp.txt", "r")
a.close()
papagolf@Sierra ~/My Files/My Programs/Learning/Python % python prac09_timestamp.py
papagolf@Sierra ~/My Files/My Programs/Learning/Python % stat prac09_timestamp.txt
File: prac09_timestamp.txt
Size: 10 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 2485542 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/papagolf) Gid: ( 1001/papagolf)
Access: 2017-09-10 11:10:40.979845492 +0530
Modify: 2017-09-10 11:10:40.979845492 +0530
Change: 2017-09-10 11:10:40.979845492 +0530
Birth: -
But when I change the script to actually read the data, the time stamp changed. Can you explain it?
New Python Script and output of stat after running it
papagolf@Sierra ~/My Files/My Programs/Learning/Python % cat prac09_timestamp.py
a = open("prac09_timestamp.txt", "r")
a.readlines()
a.close()
papagolf@Sierra ~/My Files/My Programs/Learning/Python % python prac09_timestamp.py
papagolf@Sierra ~/My Files/My Programs/Learning/Python % stat prac09_timestamp.txt
File: prac09_timestamp.txt
Size: 10 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 2485542 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/papagolf) Gid: ( 1001/papagolf)
Access: 2017-09-10 11:13:12.699848321 +0530
Modify: 2017-09-10 11:10:40.979845492 +0530
Change: 2017-09-10 11:10:40.979845492 +0530
Birth: -