Solved

debian linux

Posted on 2013-12-26
2
202 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

706 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

22 Experts available now in Live!

Get 1:1 Help Now