Finding the newest directory

S

sc0ri0n

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
 
S

Sam Holden

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
 
B

Ben Morrow

Quoth (e-mail address removed):
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
 
S

sc0ri0n

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
 
S

Sam Holden

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.
 
S

Sam Holden

Quoth (e-mail address removed):

...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...
 
J

Joe Smith

sc0ri0n said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top