Solved

debian linux

Posted on 2013-12-26
2
220 Views
Last Modified: 2014-01-16
Within a directory, how do I list files by the date they were edited?
0
Comment
Question by:Jack_son_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 39740933
ls -t

or (long)

ls -tl

Add -r to reverse the sort (oldest first)

ls -rt

or (long)

ls -rtl
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39740937
Something like this should do it.

<?php // RAY_temp_jack_son.php
error_reporting(E_ALL);
echo '<pre>';

// REQUIRED FOR PHP 5.1+
date_default_timezone_set('America/Chicago');

// THE SOURCE DIRECTORY
$path = getcwd() . DIRECTORY_SEPARATOR . 'RAY_junk';

// MAN PAGE: http://php.net/manual/en/function.scandir.php
$files = scandir($path);

// GET THE AGES OF ALL THE FILES
clearstatcache();
$ages  = array();
foreach ($files as $filename)
{
    // SKIP THE SUBDIRECTORIES
    if (is_dir($filename)) continue;

    // MAN PAGE: http://php.net/manual/en/function.filemtime.php
    $ages[$filename] = filemtime($path . DIRECTORY_SEPARATOR . $filename);
}

// MAN PAGE: http://php.net/manual/en/array.sorting.php
asort($ages);

foreach ($ages as $filename => $mtime)
{
    $date = date('c', $mtime);
    echo PHP_EOL . $date . ' ' . $filename;
}

Open in new window

HTH, ~Ray
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question