Help - Search - Members - Calendar
Full Version: Linux, how do I check when a file was last accessed?
The Planet Forums > General > The Lounge
gordonrp
ls -l lets me see when the file was created, how can I see or sort by last accessed.

Im wanting to delete files that have not been accessed in N days.

tia
gp
web-tiger
i had t odo something simular here a section of code, HTH

CODE
if (is_dir($dir)) {

  if ($dh = opendir($dir)) {

      while (($file = readdir($dh)) !== false) {

          if (($file != ".") && ($file != "..") && (!is_dir($file))) {

              $time_elapsed = (date("U",time()) - date("U",fileatime($dir . $file)));

              echo "<br> Filename: $file n";



              $days = $time_elapsed / 86400;



              echo "last accessed: $days ";

              echo " days ago. n";

              if ($time_elapsed > $seconds) {

               echo $file . " :: ";

              //    if (unlink($dir . $file)) {

              //        echo " <b><i>deleted</i></b> n";

              //    }

              }

          }

      }

      closedir($dh);

  }

}
gordonrp
Thanks allot that looks like it will do the trick. Is there a way I can see last accessed date in shell?

gp
clearsignal
ls -lu (or to sort by time ls -ltu)

I just did a 'man ls'. Cripes, ls will do a lot...way to many to remember off the top of ones head icon_biggrin.gif
gordonrp
thx
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.