Re: How to sort the output from find

From: Bryan Dongray (btd_at_dongrays.com)
Date: 09/21/03


Date: Sun, 21 Sep 2003 12:52:25 -0500

Julia Bell wrote:
> I'm using "find" to find a set of filenames that include a particular
> string. But, then I need a way to sort that list by date (ls -lrt of
> all the files that would found).
>
> Is there a straightforward way to do that?

If you're using Linux, the "stat" command is good for that:
        find [...whatever...] -print | xargs stat -t | sort +11n
which tells sort to order based on the mtime column.

I do not know if all UNIX variants have "stat", or if they do if
that option exists or has the same column format. I have:
        % uname -a
        Linux tornado 2.4.20-20.9 #1 Mon Aug 18 11:45:58 EDT 2003 i686 i686 i386 GNU/Linux
        % stat --version
        stat (coreutils) 4.5.3
        Written by Michael Meskes.
        
        Copyright (C) 2002 Free Software Foundation, Inc.
        This is free software; see the source for copying conditions. There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



Relevant Pages

  • Re: Calculate the time of last modification of a file
    ... The following code achieves the same on Linux: ... # please check your systems 'stat' command! ... echo -n yes ...
    (freebsd-questions)
  • Help on OS assigment
    ... The objective of this assignment is to understand the UNIX ... The UNIX find command is a handy tool in the system ... names of all the files that meet the selection criteria specified. ... is a system call by name stat that will do this job. ...
    (comp.unix.programmer)
  • Problem with stat and nfsmounts using kernel 2.6.21+
    ... I've got a problem with stat after updating my linux kernel from 2.6.18 to 2.6.21.3 ... After updating to kernel version 2.6.21.3 find no longer stays at local drive and goes down in all paths mounted via nfs. ... I recognized that stat now no longer handles filesystems mounted via nfs to / with a different device id. ... stat /tmp/ | grep Device ...
    (Linux-Kernel)
  • Re: "Could not stat resume device file"
    ... cannot stat it. ... During boot, at first /dev does not exist and is created empty, then populated. ... Most systems load an "initrd", an initial ram disk, imediately after loading the kernel. ... The command, /etc/init.d/rcS in my case, ...
    (Debian-User)
  • Re: Directories with 2million files
    ... Eric Anderson wrote: ... I probably should look at the source code to see if that's really ... Another option is to use the `stat' command instead of `ls'. ...
    (freebsd-current)