- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to ls inclusive year
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2003 12:17 AM
04-01-2003 12:17 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2003 12:31 AM
04-01-2003 12:31 AM
SolutionI 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2003 12:51 AM
04-01-2003 12:51 AM
Re: how to ls inclusive year
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";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2003 12:55 AM
04-01-2003 12:55 AM
Re: how to ls inclusive year
if you have cpu power enough you can use these standard commands:
# echo
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2003 01:11 AM
04-01-2003 01:11 AM
Re: how to ls inclusive year
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?