Solved

debian linux

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
block mails from a particular country in postfix 7 52
Change a button after e-mail 4 22
PHP Curl Problem 10 42
DB2 9.7 Grant Execute SP 4 18
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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