1833847 Members
2245 Online
110063 Solutions
New Discussion

Re: remove

 
SOLVED
Go to solution
tom quach_1
Super Advisor

remove

Hi all,


i just want this script to search for files only and remove it, not goes down to folder level.
can someone help please.
Thanks,
Tom


$find /tmp –mtime +8 –exec rm {} \;
8 REPLIES 8
Mel Burslan
Honored Contributor

Re: remove

if you do not want to delete the files under the directories just at the /tmp level

cd /tmp
for file in `ls -1`
do
if [ -f ${file} ]
then
rm $file
fi
done


this should do it. A bit longer but safe way of removing only regular files not anything else.
________________________________
UNIX because I majored in cryptology...
Pete Randall
Outstanding Contributor
Solution

Re: remove

find /tmp/* -prune -mtime +8 -exec rm {} \;

I think that gives what you want!


Pete

Pete
Mel Burslan
Honored Contributor

Re: remove

sorry.. I did not notice the 8 days modification time part. I am not sure right off the top of my head not to incorporate it into my little code snippet
________________________________
UNIX because I majored in cryptology...
Pete Randall
Outstanding Contributor

Re: remove

Better yet:

find /tmp/* -prune -mtime +8 -exec rm {} \;

Try it with ll instead of rm first.


Pete

Pete
tom quach_1
Super Advisor

Re: remove

thanks-Mel and Pete.

Pete, that is what i am looking for

Thanks all.

Regards,
Tom
Pete Randall
Outstanding Contributor

Re: remove

I just noticed that I cut and pasted the exact same command. Meant to say:

find /tmp/* -type f -prune -mtime +8 -exec rm {} \;


Pete

Pete
Muthukumar_5
Honored Contributor

Re: remove

You can also try as,

$cd /tmp;find . \( -name . \) -mtime +8 -exec rm {} \;

or

$cd /tmp;find . \( -name . \) -mtime +8 | xargs rm -f


hth.
Easy to suggest when don't know about the problem!
Bill Hassell
Honored Contributor

Re: remove

Just to protect unwanted files from getting deleted, I always code the -exec rm as -exec echo rm so I can see what will happen without actually removing anything. If it works correctly, then repeat the command without the echo.


Bill Hassell, sysadmin