Operating System - HP-UX
1844254 Members
2707 Online
110230 Solutions
New Discussion

Searching for files by date created

 
SOLVED
Go to solution
Gbenu
Advisor

Searching for files by date created

Hello All,
Please i need to write a script that searches for files by date created or modified to enable me decide on which one to delete.

The problem is i dont know how to use grep or any other command to search for files by date created or modified.

Thanks
Laerning is Continious, knowledge is Limitless
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: Searching for files by date created

The command you'll need to use is 'find'. The option to find that you need is '-mtime'. Do a 'man find' for more details.

Note that the modified time is most likely what you'll need since HP-UX does not keep track of the time the file was created.

James R. Ferguson
Acclaimed Contributor

Re: Searching for files by date created

Hi:

You can use 'find' with the 'newer' option:

For example, to find files modified/created on February 21, 203:

# touch 02202359 /tmp/ref1 ...Feb 20 at 2359
# touch 02220000 /tmp/ref2 ...Feb 22 at 0000

# find /tmp -xdev -type f \( -newer /tmp/ref1 -a ! -newer /tmp/ref2 \) | xargs ls -l

Regards!

...JRF...
Rajeev  Shukla
Honored Contributor
Solution

Re: Searching for files by date created

you can use find command to see the files you want to delete or take action on.
like
find ./ -mtine +2 -exec ll {}\;
to see the files older than 2 days in the current directory and
find ./ -mtine +2 -exec rm {}\ ; to delete thos files older than 2 days.
go through the man of find command to do more ..

Rajeev
Gbenu
Advisor

Re: Searching for files by date created

Thank you Guys,

The find command is just wonderful. I have the script now and its working fine.

Gbenu
Laerning is Continious, knowledge is Limitless