I want to remove files but only if they are owned by a certain user and group.
Basically I have this:
find /var/spool/greylist -mmin +363 -exec rm -f {} ;
I want to make sure it only deletes files owned by mail. Basically no matter what weird characters are in the file names I want to make sure it does not delete anything outside of /var/spool/greylist. I can add 'sudo -u' to it but then my secure log gets filled with entries but perhaps thats the only way to do it.
Matt
On Mar 10, 2009, at 10:39 AM, Matt wrote:
I want to remove files but only if they are owned by a certain user and group.
Basically I have this:
find /var/spool/greylist -mmin +363 -exec rm -f {} ;
I want to make sure it only deletes files owned by mail. Basically no matter what weird characters are in the file names I want to make sure it does not delete anything outside of /var/spool/greylist. I can add 'sudo -u' to it but then my secure log gets filled with entries but perhaps thats the only way to do it.
find /var/spool/greylist -mmin +363 -mindepth 1 -depth -user mail - group <whatever> -print0 | xargs -0 rm -f
if you want to make sure you only hit files, and not directories, do this:
find /var/spool/greylist -mmin +363 -mindepth 1 -depth -user mail - group <whatever> -type f -print0 | xargs -0 rm -f
to be extra safe, and preview what files will be deleted first:
find /var/spool/greylist -mmin +363 -mindepth 1 -depth -user mail - group <whatever> -type f -print0 | xargs -0 ls -al
-steve
-- If this were played upon a stage now, I could condemn it as an improbable fiction. - Fabian, Twelfth Night, III,v
From: Matt lm7812@gmail.com
I want to remove files but only if they are owned by a certain user and group. Basically I have this: find /var/spool/greylist -mmin +363 -exec rm -f {} ; I want to make sure it only deletes files owned by mail. Basically no matter what weird characters are in the file names I want to make sure it does not delete anything outside of /var/spool/greylist. I can add 'sudo -u' to it but then my secure log gets filled with entries but perhaps thats the only way to do it.
Try -user and -group
JD
On Tue, 10 Mar 2009, Matt wrote:
I want to remove files but only if they are owned by a certain user and group.
Basically I have this:
find /var/spool/greylist -mmin +363 -exec rm -f {} ;
Find supports -user and -group arguments, e.g.,
find /var/spool -user mail -group mail -mmin ....
On Tue, Mar 10, 2009 at 10:39 AM, Matt lm7812@gmail.com wrote:
I want to remove files but only if they are owned by a certain user and group.
Basically I have this:
find /var/spool/greylist -mmin +363 -exec rm -f {} ;
I want to make sure it only deletes files owned by mail. Basically no matter what weird characters are in the file names I want to make sure it does not delete anything outside of /var/spool/greylist. I can add 'sudo -u' to it but then my secure log gets filled with entries but perhaps thats the only way to do it.
Matt
I don't see anything in that find statement that selects the user and group combination you say you are looking for. I think you are looking for the -user and -group options. Also, if you want to see what it's going to do beforehand, don't go into it blind and use the -print option instead of the -exec. Once you know that -print only prints the files you want to delete, then you can switch -print to -exec. find /var/spool/greylist -user joe -group devs -print
However, if you have files with spaces or other special characters in the name, you will need to quote the {}, or the better thing to do is to use xargs with null delimiters, like so: find /var/spool/greylist -user joe -group devs -print0 | xargs -0 rm -f
If you need to use sudo, you can put the sudo in the xargs, and it will only get called every so often, instead of once per file: find /var/spool/greylist -user joe -group devs -print0 | sudo xargs -0 rm -f