Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scripting 1

Status
Not open for further replies.

help911

Technical User
Aug 31, 2003
7
0
0
US
How do you write a perl script that accept a directory name as a command line argument and then looks at all of the files in that directory to fined the oldest file. Print out the name of the file and the age of that file in days. If no directory name is listed on the command line perform the check on the current directory.

Thank you for your help
 
ok, I'll start you off :)

[tt]
#!/usr/local/bin/perl

# get the directory to work with
my $dir = shift || $dir = '.';
chdir $dir || die "Can't cd to directory $dir\n$!\n";

# get a list of all files in that directory
while(<*>){
[tab]# filename is in $_ in this loop
[tab]# retrieve the file details, including age...
[tab]@filedetails = stat($_);
[tab]# and keep track of the oldest file....
}
[/tt]
You should be aware that:

File creation time is not stored by UNIX system, a modification time is stored, and that *may* relate to the creation time - but may relate to the time the file was renamed. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top