1834271 Members
95394 Online
110066 Solutions
New Discussion

Find Command

 
SOLVED
Go to solution
Global Server Operation
Frequent Advisor

Find Command

I need to do the following:
Please remove files ending with extension *.out, *.prn & *.qte from /users folder on server which are not created, modified or touched last 2 days

I haven't much experience in with this type of request. Can someone recommned a way to do this? All replies are appreciated.
3 REPLIES 3
RAC_1
Honored Contributor

Re: Find Command

find /users -name "*.out" \;

You can add -exec {} to remove the file.
find /users -type f -name "*.out" -exec rm {} \;
There is no substitute to HARDWORK
Fred Ruffet
Honored Contributor
Solution

Re: Find Command

find /users -type f -name "*.out *.prn *.qte" -atime +2 -a -name "*.out *.prn *.qte" -mtime +2 -exec ls -ld {} \;

This first command will list files. You will then be able to see if it's exactly what you want. You should be carrefull about date displayed as long as +2 means 2*24 hours so if does not correspond to "2 days ago before midnight"... If OK, then replace ls by rm like this :
find /users -type f -name "*.out *.prn *.qte" -atime +2 -a -name "*.out *.prn *.qte" -mtime +2 -exec rm {} \;

Regards,

Fred

--

"Reality is just a point of view." (P. K. D.)
Steven E. Protter
Exalted Contributor

Re: Find Command

its really all in the man page for find

find /users

You want to use the mtime directive

Here is an example

find ${TmpDirList} -type f -mtime +${OLDEST} -print | \
sed -f ${ExceptSed} > ${RemoveList} 2>/dev/null


The variable $OLDEST is the number of days. The sed part processes previously created lists of files. TmpDirList is a list of directoories to check.

All you need to do is parse the output for the extensions you want to process.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com