Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Getting modification dates of files

I have a script, that needs to do a glob() type list, and get not only file names, but their modification dates as well.  I will use this to search through a directory, and delete files that were modified over a day ago.
0
7thwave
Asked:
7thwave
  • 2
1 Solution
 
ozoCommented:
In what language is the script written?
0
 
7thwaveAuthor Commented:
The script is in perl
0
 
ozoCommented:
(stat $filename)[9]
is the modification date
-M $filename
is the number of days since it was last modified (at the time the script was started)
0
 
RoboBobCommented:
#!/usr/local/bin/perl -w
#####################
foreach $file (</put/dir/here/*>) {
    if(-M $file > 1) { unlink($file); }
}

or, do it the easy way, from the command line with find...
find -mtime +1 -exec rm {} \;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now