Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

debian linux

Posted on 2013-12-26
2
Medium Priority
?
232 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 1000 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 111

Accepted Solution

by:
Ray Paseur earned 1000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

877 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