FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 03-10-2009, 01:39 PM
Matt
 
Default rm user:group

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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-10-2009, 01:59 PM
Steve Huff
 
Default rm user:group

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




_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-10-2009, 02:01 PM
John Doe
 
Default rm user:group

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




_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-10-2009, 02:01 PM
Paul Heinlein
 
Default rm user:group

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 ....

--
Paul Heinlein <> heinlein@madboa.com <> http://www.madboa.com/
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-10-2009, 02:03 PM
Brian Mathis
 
Default rm user:group

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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 06:22 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org