Operating System - HP-UX
1834646 Members
2540 Online
110069 Solutions
New Discussion

Re: how to ls inclusive year

 
SOLVED
Go to solution
David_246
Trusted Contributor

how to ls inclusive year

Hi,

Just tried to find out how to get always a year noted in an "ls -l".
This because I need to compare dates within perl of backup files with original files. Now it's the issue that sometimes you have 8 colums and sometimes 9. Very hard to compair :)

Anyone an idea how to do this ? I read the man-page of ls, but couldn't find anything appropriate.

Regs David
@yourservice
4 REPLIES 4
Solution

Re: how to ls inclusive year

While this doesn't answer your original question (and I don't know of a way either, sorry) I think it answers your underlying problem.
I would sugest that if you need file date info in perl, the stat() and lstat() functions return a 13 element array which include as members, the atime, mtime and ctime of the file. "man perlfunc" will give you more info on these functions.

Regards,
Stephen
David_246
Trusted Contributor

Re: how to ls inclusive year

Thanks !!

This results in :

#!/usr/contrib/bin/perl

$dir="/root/home/";
$savedir="${dir}/save/";
$testfile="${savedir}tar_uitwijk.tar";

@tst=`/usr/bin/tar tvf $testfile`;

foreach $line(@tst) {
($size,$month,$day,$time,$year,$file)=(split(/\s+/, $line))[2,3,4,5,6,7];
$file=substr($file,+2);
$oldfile="${dir}${file}";
$check_file="${dir}${file}";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$csize,$atime,$mtime,$ctime,$blksize,$blocks)= stat($check_file);
($sec, $min, $hour, $mday, $mon, $myear, $wday, $yday, $isdst)= localtime($mtime);
$myear= 1900 + $myear;

print "File: $oldfile has size $size and has has a modify time of: $time and a modify date : $day $year\n";
print "File: $check_file has size $csize and has has a modify time of: ${hour}:${min} and a modify date : $mday $myear\n\n";
}
@yourservice
john korterman
Honored Contributor

Re: how to ls inclusive year

Hi David,
if you have cpu power enough you can use these standard commands:
# echo | cpio -o 2>/dev/null|cpio -ivt 2>/dev/null|awk '{print $7,$4,$5,$6}'

regards,
John K.

it would be nice if you always got a second chance
Ralph Grothe
Honored Contributor

Re: how to ls inclusive year

Just some supplementary waffling about Perl's stat().

If you are only interested in parts of a list any Perl function returns it's less cumbersome to use slices or simply discard unwanted list entries.

e.g.

my ($mday, $mon, $year) = (localtime)[3..5];

or if you don't like the strange bracketing owe to slicing use the discarding strategy

(undef, undef, undef, $mday, $mon, $year) = localtime;

Read some POD for details

perldoc perldsc
perldoc perllol
perldoc -f -x
perldoc -f stat
perldoc -f localtime

You can use the more readable file test operators instead of using stat
(see "perldoc -f -x")

Finally a word of warning regarding the HP shipped Perl under /usr/contrib
It used to be a rather dated Perl 4 which couldn't even cope with references.

Make sure you set your PATH to the more current Perl which possibly also already is installed on your box (usuallay under /opt)
What is "swlist perl" responding?


Madness, thy name is system administration