Finding the newest directory

Discussion in 'Perl Misc' started by sc0ri0n, May 13, 2004.

  1. sc0ri0n

    sc0ri0n Guest

    Hi,

    If I have a bunch of directories and files (sun solaris). Is there a way to
    find the newest directory (last one created not modified)?

    TIA
    sc0ri0n, May 13, 2004
    #1
    1. Advertising

  2. sc0ri0n

    Sam Holden Guest

    On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <> wrote:
    > Hi,
    >
    > If I have a bunch of directories and files (sun solaris). Is there a way to
    > find the newest directory (last one created not modified)?


    No (unless you are using a funky non-standard file system).

    Creation time is not tracked by the filesystem.

    You have (most recent) access time, modification time, and
    file status time. File status time (ctime) is as close as
    you'll get, but it is set by other operations that change
    the file status (such as chmod(), link(), unlink(), etc.)

    stat gives you access to the ctime.

    perldoc -f stat

    --
    Sam Holden
    Sam Holden, May 13, 2004
    #2
    1. Advertising

  3. sc0ri0n

    Ben Morrow Guest

    Quoth :
    > On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <> wrote:
    > > Hi,
    > >
    > > If I have a bunch of directories and files (sun solaris). Is there a way to
    > > find the newest directory (last one created not modified)?

    >
    > No (unless you are using a funky non-standard file system).
    >
    > Creation time is not tracked by the filesystem.
    >
    > You have (most recent) access time, modification time, and
    > file status time. File status time (ctime) is as close as
    > you'll get, but it is set by other operations that change
    > the file status (such as chmod(), link(), unlink(), etc.)
    >
    > stat gives you access to the ctime.


    ....and you'll likely want File::Find to do the searching.

    OTOH, you could probably do this more easily with find(1).

    Ben

    --
    For the last month, a large number of PSNs in the Arpa[Inter-]net have been
    reporting symptoms of congestion ... These reports have been accompanied by an
    increasing number of user complaints ... As of June,... the Arpanet contained
    47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
    Ben Morrow, May 13, 2004
    #3
  4. sc0ri0n

    sc0ri0n Guest

    Sam,

    I am not interested in files at all. There is a process that creates
    directories. What I need to do is to detect the one created last and move
    all of its content.

    Also, I am new to unix so I am not sure if there are other statistics for
    directories like last modified or last accessed as in files?

    Thanks,
    Pete


    "Sam Holden" <> wrote in message
    news:...
    > On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <> wrote:
    > > Hi,
    > >
    > > If I have a bunch of directories and files (sun solaris). Is there a way

    to
    > > find the newest directory (last one created not modified)?

    >
    > No (unless you are using a funky non-standard file system).
    >
    > Creation time is not tracked by the filesystem.
    >
    > You have (most recent) access time, modification time, and
    > file status time. File status time (ctime) is as close as
    > you'll get, but it is set by other operations that change
    > the file status (such as chmod(), link(), unlink(), etc.)
    >
    > stat gives you access to the ctime.
    >
    > perldoc -f stat
    >
    > --
    > Sam Holden
    sc0ri0n, May 13, 2004
    #4
  5. sc0ri0n

    Sam Holden Guest

    On Wed, 12 May 2004 23:12:08 -0400, sc0ri0n <> wrote:
    > Sam,
    >
    > I am not interested in files at all. There is a process that creates
    > directories. What I need to do is to detect the one created last and move
    > all of its content.


    Directories are just files, just like block devices are just files.

    >
    > Also, I am new to unix so I am not sure if there are other statistics for
    > directories like last modified or last accessed as in files?


    Directories are just files. They have all the same metadata.

    [snip full quote, sigs and all]

    Please don't do that, put your reply after the text you
    are replying to - trim irrelevant text if it's too long.

    --
    Sam Holden
    Sam Holden, May 13, 2004
    #5
  6. sc0ri0n

    Sam Holden Guest

    On Thu, 13 May 2004 03:09:51 +0000 (UTC),
    Ben Morrow <> wrote:
    >
    > Quoth :
    >> On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <> wrote:
    >> > Hi,
    >> >
    >> > If I have a bunch of directories and files (sun solaris). Is there a way to
    >> > find the newest directory (last one created not modified)?

    >>
    >> No (unless you are using a funky non-standard file system).
    >>
    >> Creation time is not tracked by the filesystem.
    >>
    >> You have (most recent) access time, modification time, and
    >> file status time. File status time (ctime) is as close as
    >> you'll get, but it is set by other operations that change
    >> the file status (such as chmod(), link(), unlink(), etc.)
    >>
    >> stat gives you access to the ctime.

    >
    > ...and you'll likely want File::Find to do the searching.
    >
    > OTOH, you could probably do this more easily with find(1).


    I thought about find(1), but it finds all the files that match
    the expression you give it. I don't know how to tell it to
    output just the newest, or the biggest, of the anythingest for
    that matter.

    My first guess would be something like:

    my $the_winner;
    {
    my $the_winners_ctime;
    for (get_the_directory_paths()) {
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks) = stat;
    if (!defined $the_winner or $the_winners_ctime < $ctime) {
    $the_winner = $_;
    $the_winners_ctime = $ctime;
    }
    }
    }
    print "$the_winner\n";

    But ctime gets set by write(2) so the whole thing is pointless...

    --
    Sam Holden
    Sam Holden, May 13, 2004
    #6
  7. sc0ri0n

    Joe Smith Guest

    sc0ri0n wrote:

    > Sam,
    >
    > I am not interested in files at all. There is a process that creates
    > directories. What I need to do is to detect the one created last and move
    > all of its content.
    >
    > Also, I am new to unix so I am not sure if there are other statistics for
    > directories like last modified or last accessed as in files?


    foreach my $entry (glob '*') {
    print +(-d $entry ? 'Directory' : 'File'), " $entry is ", -s _, " bytes\n";
    printf " Modified %6.2f days ago\n", -M _;
    printf " Accessed %6.2f days ago\n", -A _;
    printf " Changed %6.2f days ago\n", -C _;
    }

    -Joe
    Joe Smith, May 13, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    How use newest userid in auto INSERT (2.0)

    VB Programmer, Jan 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,801
    VB Programmer
    Jan 13, 2006
  2. Michael Kintner
    Replies:
    0
    Views:
    847
    Michael Kintner
    Nov 30, 2003
  3. Mmcolli00 Mom

    Show newest file in directory?

    Mmcolli00 Mom, Dec 18, 2008, in forum: Ruby
    Replies:
    6
    Views:
    116
    Robert Klemme
    Dec 19, 2008
  4. jordilin
    Replies:
    17
    Views:
    191
    Peter J. Holzer
    Oct 29, 2007
  5. Stu
    Replies:
    10
    Views:
    192
    Tad J McClellan
    Oct 13, 2008
Loading...

Share This Page