Operating System - HP-UX
1833838 Members
2713 Online
110063 Solutions
New Discussion

list files on a certain date !

 
SOLVED
Go to solution
Tung Dang
Advisor

list files on a certain date !

Dear Sirs,
Please give me the command to:
1. List all fies generated in on file system on a certain date.
2. Count all fies generated in on file system on a certain date.
3. Calculate the total of space for all fies generated in on file system on a certain date.

thank a lot
Tung
24 REPLIES 24
A. Clay Stephenson
Acclaimed Contributor

Re: list files on a certain date !

This absolutely, positively cannot be done. UNIX has no notion of the creation date of a file. Unless you create a database that stores this information, you have no way of knowing this. You do have 3 timestamps: modification time (last data change); change time (last meta-data change); and last access time.

In order to find files modified on a certain date, use the touch command to create two reference files: /tmp/F1 - mtime = 1 second before the start of the target day and /tmp/F2 mtime = 1 second after the end of the target day. You then use the find command with -older and -newer options:

Something like this:

find / -type f \( -newer /tmp/F1 -a -older /tmp/F2 \) -exec ls -l {} \;

Man touch and find for details.
If it ain't broke, I can fix that.
Reshma Malusare
Trusted Contributor

Re: list files on a certain date !

Hi tung,

To display each file's creation date, last access date, and last modification date for the files stored, use the SHOW=DATES option.
For example:
:FILE T;DEV=TAPE
:STORE @.PUB.DOC;*T;SHOW=DATES

Refer following documnet for detail information:

http://docs.hp.com/en/32650-90484/ch06s03.html


Thanks & Regards
Reshma
Reshma Malusare
Trusted Contributor

Re: list files on a certain date !

Hi Tung,

In HP-unix we have access, modify time stamps..

1] touch --> update access, modification, and/or change times of file

syntax:
touch [-amc] [-r ref_file | -t time] file_name...

Refer below document:
http://docs.hp.com/en/B2355-60130/touch.1.html

2] find --> find files according to option given..

Here you can go for -atime, -mtime, -newer options to fulfil the requirements

Refer below document for options description:
http://docs.hp.com/en/B2355-60130/find.1.html
http://docs.hp.com/en/B2355-60130/findstr.1.html

Thanks & Regards
Reshma
Tung Dang
Advisor

Re: list files on a certain date !

Dear Sirs,
Thank you for your quickly responses.
I think when a new file is created, the creation time is the same with modified time. So can we use -mtime in find command to list all file in a certain day. For example, I want to list all file generated on yesterday from one directory.
Can we use combination of find and grep for that purpose?
Reshma, sorry I dont understand much about SHOW parameter.

Thanks a lot
Tung
A. Clay Stephenson
Acclaimed Contributor

Re: list files on a certain date !

Think what you like. If the ctime or mtime happens to be the time that a file was created; it is nothing more and nothing less than coincidence. If you know the time a file was created, it is only an accident. If you want a different answer then change the question because the question as stated cannot be answered.
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>Reshma: :STORE @.PUB.DOC;*T;SHOW=DATES

That's for MPE/iX, not HP-UX. And you would want to send the tape output to $NULL.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Mr.Stephenson,
Every day, our Oracle database create a lot of archive files. So I just want to list out all files created by a certain day. For example, list all file created on 26-Jun-2007. And count them. And calculate the total space of them.

Sorry Reshma,
Our system is HPUX.

Thank you very much for your answers.
Tung
Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>Every day, our Oracle database create a lot of archive files.

If these files are created and never modified, then you can use -mtime.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Sirs,
Thanks a lot for your reply.
I tried as what you recomended:
# touch -amt 0706252359 temp1.touch
# touch -amt 0706270000 temp2.touch
#find . -type f \( -newer temp1.touch -a ! -newer temp2.touch \) -exec ll {} \;

The output display the list of files I needed but I dont know why it also display the temp2.touch file here.

Do you have any ideas about that?

Tung
Dennis Handly
Acclaimed Contributor
Solution

Re: list files on a certain date !

>-exec ... {} \;

You should use "{} +" instead, not "{} \;".

>but I dont know why it also display the temp2.touch file here.

Because the ! -newer test is >= not >. You are going to have to grep out that boundary value. This is elementary C++ STL programming.

So strictly speaking the second reference file must be in the time range you want and the first not.
touch -amt 0706262359 temp2.touch

This gets every file modified on June 26.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Mr.Dennis,
Thank you very much for your explain.
if we use:
touch -amt 0706262359 temp2.touch
Do we lost some files created from 0706262359.01 second to 07062359.59 second?

rgds,
Tung
Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>Do we lost some files created from 0706262359.01 second to 07062359.59 second?

Sorry, you're right, both should be:
# touch -amt 0706252359.59 temp1.touch
# touch -amt 0706262359.59 temp2.touch
Tung Dang
Advisor

Re: list files on a certain date !

Dear Sirs,
Thank you very much for your help.
I have another question, how can I calculate the total space of those files?

Regards,
Tung
A. Clay Stephenson
Acclaimed Contributor

Re: list files on a certain date !

Simple,

find .... -exec ls -l {} \; | awk '{tot += ($5 + 0)} END {printf("%10d\n",tot)}'
If it ain't broke, I can fix that.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Sirs,
Thanks for your help.
When I try use "\;" for the find command as following:
find . -type f -newer temp1.touch -a ! -newer temp2.touch -exec ll {} \;
I got the result as my expect.
But if I use "\+" al following:
find . -type f -newer temp1.touch -a ! -newer temp2.touch -exec ll {} \+
nothing was display.
Another question, if I use this command: find . -type f -newer temp1.touch -a ! -newer temp2.touch -exec ls -lt {} \; the sort ("-t")not happend for the result.
Could you please explain me why?
Rgds
Tung
Hein van den Heuvel
Honored Contributor

Re: list files on a certain date !

>> But if I use "\+" al following:

Re-read dennis's reply... no \, just +

>> Another question, if I use this command: find . -type f -newer temp1.touch -a ! -newer temp2.touch -exec ls -lt {} \; the sort ("-t")not happend for the result.

It is happening... 1 file at a time.
You are asking ls -lt to operate on the file just found. The one file.

I would just feed the found files into an awk/perl/shel script to add up the details and display. For example:


$ find xx -newer begin ! -newer end | perl -ne 'print; chomp; $s+=-s}{print "$. files, $s bytes\n"'
$ find xx -newer begin ! -newer end | xx/a
xx/x.awk
xx/b
xx/aa
4 files, 1808 bytes

SMOP to change layout, report MB or GB.

Cheers,
Hein




Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>But if I use "\+" as following:
find . -type f -newer temp1.touch -a ! -newer temp2.touch -exec ll {} \+
nothing was display.

I can't explain that. It works fine for me, with "+" or with ";". I get the same number of files.

>the sort ("-t") not happend for the result.
Could you please explain me why?

Because you are not sorting ALL of the files at the same time. Even with +.

Since you are getting the results for just one day, you could just sort on the time field: sort -k8,8

>Hein: Re-read dennis's reply... no \, just +

That shouldn't make a difference but as a purest, you shouldn't have the backslash and I've asked that the man page be fixed.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Mr.Hein Van Den,
Thanks for your explain and your script.
Dear Mr.Dennis,
Thanks for your kindly help.
Please see the following:
[root@COVIS1:/tmp]find . -newer temp1.touch -a ! -newer temp2.touch -exec ll {} \;
-rw------- 1 root sys 10225 Jun 27 17:18 ./mana01910
total 0
srwxrwxrwx 1 cc tuxedo 0 Jun 27 22:05 agent.17125
srwxrwxrwx 1 cc tuxedo 0 Jun 27 22:05 ./ssh-iVPpd17125/agent.17125
-rw-r--r-- 1 root sys 0 Jun 27 23:59 ./temp2.touch
-rw------- 1 root sys 14889 Jun 27 17:18 ./cata01910
[root@COVIS1:/tmp]find . -newer temp1.touch -a ! -newer temp2.touch -exec ll {} +
[root@COVIS1:/tmp]find . -newer temp1.touch -a ! -newer temp2.touch -exec ls {} +
[root@COVIS1:/tmp]find . -newer temp1.touch -a ! -newer temp2.touch -exec ls -l {} +
./cata01910 ./mana01910 ./ssh-iVPpd17125/agent.17125 ./temp2.touch

./ssh-iVPpd17125:
agent.17125
As you see, when I use "-exec ll {} \;", it worked; but when I use "-exec ll {} +", nothing display in the result; when I use "-exec ls {} +", nothing display also; but when I use "-exec ls -l {} +", it worked.
I think there is a relationship between "ll /ls" command with "{} \;" or "{} +".
Is it right? Could you please explain for me.
Thanks again
Tung
Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>Please see the following:

I see it but it doesn't happen for me.

>I think there is a relationship between "ll /ls" command with "{} \;" or "{} +".
Is it right? Could you please explain for me.

I don't see how but use this:
$ find . -type f -newer temp1.touch -a ! -newer temp2.touch \
-exec /usr/bin/ll +

Don't use \ before the + or {} and use an absolute path for ll and find only files.
Tung Dang
Advisor

Re: list files on a certain date !

Dear Sirs,
Thank you for your help.

I really confuse of using {} for -exec option of the find command. I dont know when can I use {} and when not. And how to use it with "+".
Could you please help me understanding it clearly.

Thanks and Best regards,
Tung
Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

Did removing the {} make it work?
Did the absolute path (for ll) help?

>I really confuse of using {} for -exec option of the find command. I dont know when can I use {} and when not. And how to use it with "+".

You don't need {} with + but Posix requires it.
And you need {} for ";".
Tung Dang
Advisor

Re: list files on a certain date !

Dear Mr.Dennis,
Thank you for your help.
>Did removing the {} make it work? Yes
>Did the absolute path (for ll) help? No, no absolute path still worked.

Now I know how to solve this issues.

Thanks a lot

Dennis Handly
Acclaimed Contributor

Re: list files on a certain date !

>Now I know how to solve this issues.

That's great. Please read the following about assigning points:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
Tung Dang
Advisor

Re: list files on a certain date !

Thanks again for your helps. I close this case now.

Tung