[K12OSN] scripting trash removal

Petre Scheie petre at maltzen.net
Mon Jan 30 21:35:28 UTC 2006



Mike Ely wrote:
> Toshio Kuratomi wrote:
> 
>> On Fri, 2006-01-27 at 13:22 -0500, Mark Gumprecht wrote:
>>
>>> Dave was nice to send me this for clearing cache
>>>
>>> !#/bin/bash
>>> for x in `ls /home`; do
>>> echo "Doing $x ..."
>>> cd /home/${x}/.mozilla/firefox/*.default/Cache
>>> rm -Rf *
>>> done
>>>
>>> Ok that works just fine. Soooo, If that works for cache, with a 
>>> little mod like this
>>>
>>> !#/bin/bash
>>> for x in `ls /home`; do
>>> echo "Doing $x ..."
>>> cd /home/${x}/.Trash
>>> rm -Rf *
>>> done
>>
>>
>> You've probably already considered this but just in case:
>>
>> Deleting cache files should be relatively transparent to an end-user (It
>> affects their performance somewhat but they shouldn't lose data.)
>> Deleting the contents on .Trash is unexpectedly circumventing the way
>> the Trash works (to be able to recover deleted files.)
>>
>> If you hadn't already considered that, you might want to implement aging
>> of the Trash (like the tmpwatch program for /tmp) or user quotas (so the
>> user has to empty the Trash themselves in order to stay under quota.)
>>
>> -Toshio
> 
> 
> That's a good point.  However, the vast majority of users do not use 
> their Trash (or Recycle Bin) correctly at all.  I'm sure many in here 
> can recount numerous times where they found a user with a couple of gigs 
> of general rubbish in their trash.  Most people delete stuff and never 
> ever empty.  Yeah, there was that one lady who freaked when I emptied 
> her trash (it's almost a nervous habit for me when sitting down at a 
> desktop).  Apparently she was actually using it as a folder to store 
> stuff.  D'oh!
> 
> Mike
> 
Taking the above into consideration, how about this:

!#/bin/bash
for x in `ls /home`; do
echo "Doing $x ..."
find /home/${x}/.Trash -atime +30 -exec rm -f {}\;
done

This will search each user's ~/.Trash directory for files that have not been accessed 
for at least 30 days and delete any it finds.  If a user has no .Trash directory, it 
just spits out an error.   If you want to test it just to make sure it's going to remove 
the correct files, replace the 'rm -f' part with, say, 'ls -l' and it will just display 
the files.  Once you're sure it will pick the correct files, change back to 'rm -f'.

Petre




More information about the K12OSN mailing list