Last modified time of the folder is changing when I view the file inside the directory

Hi.,

Last modified time of the folder is changing when I view the file inside the directory. Here is the test on sample directory. I believe that ls -l commands gives the time detail w.r.t last modified time. Pl. suggest.

bash-3.2$ mkdir test
  bash-3.2$ cd test
  bash-3.2$ touch myfile.txt
  bash-3.2$ ls -l
  total 0
  -rw-r--r-- 1 avv avvgrp 0 Nov 26 03:51 myfile.txt
   
  bash-3.2$ cd ..
   
  bash-3.2$ ls -l test/
  total 0
  -rw-r--r-- 1 avv avvgrp 0 Nov 26 03:51 myfile.txt 



bash-3.2$ ls -lrt | tail -1 

drwxr-xr-x 2 avv avvgrp  4096 Nov 26 03:51 test
   
  bash-3.2$ vi test/myfile.txt
   
   
  q!   ---- here I have not modified the file. And executed quit without saving command. 

   
  bash-3.2$ ls -lrt | tail -1
  drwxr-xr-x 2 avv avvgrp  4096 Nov 26 03:53 test

Timestamp of the folder has changed after I viewed the file, as indicated above. Pl. suggest.

Thanks.,

man stat
stat yourfolder
1 Like

When you open a file with vi a hidden swap-file is created (to recover your vi-session in case vi crashes). That file is deleted when you exit vi in a normal way. That deletion (and before that the creation of the swap-file) causes the change of the timestamp.

1 Like