Operating System - Linux
1827841 Members
1725 Online
109969 Solutions
New Discussion

Need the list of files which created in specific time

 
SOLVED
Go to solution
VVS
Regular Advisor

Need the list of files which created in specific time

Hi all
I need the list of files which created in specific time.
Foe example: I need list of files in perticular directory which are created in last 1 hour.


Thanks
Work is life, you know, and without it, there's nothing but fear and insecurity.
13 REPLIES 13
Dennis Handly
Acclaimed Contributor

Re: Need the list of files which created in specific time

You can't get that info. You can only get a list of files modified in the last hour.

To do this, you would have to use touch to create a reference file of exactly one hour ago, then use "find . -newer ref-file".
James R. Ferguson
Acclaimed Contributor

Re: Need the list of files which created in specific time

Hi:

With Perl, this is easy:

# perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -M _ <= 1/24},@ARGV)' /path

THis will search the directory or directories passed as the script argument looking for FILES that were *modified* during the last hour (1/24 of a day).

By the way, there is no such thing as a creatino timestamp in Unix. The 'mtime' or last modification timestamp is equivalent to a creation moment when a file is first instantiated. Thereafter, any change in the file's contents updates the 'mtime' in its inode.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Need the list of files which created in specific time

Hi (again):

Was there something more that you wanted in your solution?

Regards!

...JRF...
OFC_EDM
Respected Contributor

Re: Need the list of files which created in specific time

Hi James,

I tried your command and it doesn't work for me. I tried both relative and absolute path.

Does this have to be run in a script or is it good to run at the prompt?


Cheers
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: Need the list of files which created in specific time

Correction

It returns nothing on HPUX 11.11

on my 11.23 (recently patched) system
it does

# /usr/bin/perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -M _ <:q= 1/24},@ARGV)' /tmp
syntax error at -e line 1, near "<:"
Can't find string terminator "=" anywhere before EOF at -e line 1.
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: Need the list of files which created in specific time

Correction

doesn work on hpux 11.11

on my 11.23 system it does th is

# /usr/bin/perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -M _ <:q= 1/24},@ARGV)' /tmp
syntax error at -e line 1, near "<:"
Can't find string terminator "=" anywhere before EOF at -e line 1.
The Devil is in the detail.
VVS
Regular Advisor

Re: Need the list of files which created in specific time

hi James
Thanks for ur reply
I have 11.11 version of HP-Ux. So will it run on the same?
And can I add this line in may script?
Another one is , Is there any cmd shows the files modified in last one hour in perticular directory

Thanks
Work is life, you know, and without it, there's nothing but fear and insecurity.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need the list of files which created in specific time

Hi (again):

> Vasu: I have 11.11 version of HP-Ux. So will it run on the same?

Yes, Perl should have been part of your 11i installation and hence my script will run.

> Vasu: Is there any cmd shows the files modified in last one hour in perticular directory?

Yes, this is the original script I posted for you. Simply pass the name of the directory you want to examine as the argument to the script. In the example I showd, I used '/path' as a generic argument label. You could use '/home' or '/home/vasu' or anything that is a directory.

> O'Kevin: Copy-and-paste my post and provide the directory or directories you are interested in examining as arguments. The absence of any output means that there were no files meeting the criteria.

Regards!

...JRF...
VVS
Regular Advisor

Re: Need the list of files which created in specific time

hi
I got following error on my system
Can't locate File/Find.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.


Please provide solution

Thanks
Work is life, you know, and without it, there's nothing but fear and insecurity.
James R. Ferguson
Acclaimed Contributor

Re: Need the list of files which created in specific time

Hi:

> I got following error on my system
Can't locate File/Find.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-

You have a very old Perl on your server. The 'File::Find' module wasn't part of the Perl Core distribution at that time.

I suggest that you download and install a current Perl. No reboot is necessary!

http://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

...and if per chance this is an old 10.20 system, Merijn has a Perl for that:

http://mirrors.develooper.com/hpux/downloads.html

Perl 5.8.8 is an excellent version for production. Perl 5.10 was recently released too.

Regards!

...JRF...

Re: Need the list of files which created in specific time

Touch a reference file (say /tmp/ref_file) with a specific timestamp that corresponds to approx 1 hr ago using:
touch -t CCYYMMDDhhmm.SS /tmp/ref_file

run a find:
find start_dir -type f -newer /tmp/ref_file

as per "man find":
-newer file True if the current file has been modified more recently than the argument file.


James R. Ferguson
Acclaimed Contributor

Re: Need the list of files which created in specific time

> Rangarajan :

Why resurrect a 10-day old thread that has a bunny and for which your alternate proposal was first suggested by someone else on the opening day?

While 'find -newer ...' certainly works, it doesn't provide the moving window of time yielded by the Perl snippet I showed. Of course, you could wrap a 'touch' and a 'find' in a small shell script that creates the reference point; performs the 'find' and then removes the (then) useless reference file.

Regards!

...JRF...
VVS
Regular Advisor

Re: Need the list of files which created in specific time

Thanks all of you for your information
Work is life, you know, and without it, there's nothing but fear and insecurity.