Solved

debian linux

Posted on 2013-12-26
2
205 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_
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 108

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now