daggett has asked for the wisdom of the Perl Monks concerning the following question:
I need to search through a large structure with saved web pages and subsidiary files, saved from firefox, most often just to find the most recently updated page from its time stamp. I prefer to use the perl stat() function, rather than the ls command as I have been using:
james@tibrogargan:~/devel/find/testdirs$ find . -type f -exec ls -l -- +time-style=+%Y%m%d {} \; -rw-rw-r-- 1 james james 7 20221013 ./d2/d2_3/f2_3_1 -rw-rw-r-- 1 james james 13 20221013 ./d2/d2_2/f2_2_2 -rw-rw-r-- 1 james james 8 20221013 ./d2/d2_2/f2_2_1 -rw-rw-r-- 1 james james 13 20221013 ./d2/f2_2 -rw-rw-r-- 1 james james 0 20221012 ./d1/d3_3/f1 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_1/f1 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_1/f3 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_1/f2 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_2/f1 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_2/f3 -rw-rw-r-- 1 james james 0 20221012 ./d1/d1_2/f2
I want to transform the above in many ways, including placing the file basename at the start, etc., etc., roughly as follows:
f2_3_1 7 20221013 ./d2/d2_3/ <directoryInodeNumber> ...
The program, I have written as my first step towards accomplishing this (less many comments and debugging statements) is:
#!/usr/bin/perl use Cwd qw(cwd); my $wDirectory = cwd; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtim +e, $ctime, $blksize, $blocks) = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0); open(README, "find $wDirectory -type f |") or die "Can't run program: +$!\n"; while(<README>) { $output = $_; ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mti +me, $ctime, $blksize, $blocks) = stat("$output"); print("stats "); print ("dev: $dev, ino: $ino, mode: $mode, nlink: $nlink, uid: $ui +d, gid: $gid, rdev: $rdev, size: $size, atime: $atime, mtime: $mtime, + ctime: $ctime, blksize: $blksize, blocks: $blocks"); print("]\n"); } close(README);
But when I execute the program I get no data whatsoever from the stat() function:
james@tibrogargan:~/devel/find/testdirs$ ~/devel/perl/findLsiCleaned.p +l stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ] stats dev: , ino: , mode: , nlink: , uid: , gid: , rdev: , size: , ati +me: , mtime: , ctime: , blksize: , blocks: ]
Can anyone see why my script does not work?
Thank you for your attention.
|
|---|