Hi All, How to easily remove some particular files from more than one directory. For example I have directories: $ ls -l total 12 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox1 drwx------+ 2 ovince None 0 Mar 7 08:30 DHbox10 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox2 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox3 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox4 drwx------+ 2 ovince None 0 Mar 7 08:31 DHbox5 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox6 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox7 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox8 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox9 from all these directories I would like to remove JUST files that finish wit suffix = 'pro' and suffix = '.dat' keeping others untouched thanks oliver -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Vince Oliver wrote:
Hi All,
How to easily remove some particular files from more than one directory. For example I have directories:
$ ls -l total 12 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox1 drwx------+ 2 ovince None 0 Mar 7 08:30 DHbox10 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox2 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox3 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox4 drwx------+ 2 ovince None 0 Mar 7 08:31 DHbox5 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox6 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox7 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox8 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox9
from all these directories I would like to remove JUST files that finish wit suffix = 'pro' and suffix = '.dat' keeping others untouched
thanks oliver
Hi Oliver, find DHbox* -name *.dat | xargs rm should do the trick. Best regards Sylvester -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 07 March 2007 at 10:49, in message <45EE98CC.20805@solidonline.dk>, Sylvester Lykkehus <zly@solidonline.dk> wrote: Vince Oliver wrote:
Hi All,
How to easily remove some particular files from more than one directory. For example I have directories:
$ ls -l total 12 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox1 drwx------+ 2 ovince None 0 Mar 7 08:30 DHbox10 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox2 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox3 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox4 drwx------+ 2 ovince None 0 Mar 7 08:31 DHbox5 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox6 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox7 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox8 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox9
from all these directories I would like to remove JUST files that finish wit suffix = 'pro' and suffix = '.dat' keeping others untouched
thanks oliver Hi Oliver, find DHbox* -name *.dat | xargs rm should do the trick.
Don't you need quotes around the *.dat to stop the shell expanding it ? GTG -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Gordon Ross wrote:
On 07 March 2007 at 10:49, in message <45EE98CC.20805@solidonline.dk>, Sylvester Lykkehus <zly@solidonline.dk> wrote: Vince Oliver wrote: Hi All,
How to easily remove some particular files from more than one directory. For example I have directories:
$ ls -l total 12 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox1 drwx------+ 2 ovince None 0 Mar 7 08:30 DHbox10 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox2 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox3 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox4 drwx------+ 2 ovince None 0 Mar 7 08:31 DHbox5 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox6 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox7 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox8 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox9
from all these directories I would like to remove JUST files that finish wit suffix = 'pro' and suffix = '.dat' keeping others untouched thanks oliver Hi Oliver, find DHbox* -name *.dat | xargs rm should do the trick.
Don't you need quotes around the *.dat to stop the shell expanding it ? That or a '\' in front.
$ find DHbox* -name "*.dat" -o -name "*.pro" -exec rm -f {} \; would do. Omit the final "-exec..." to first check that it only catches those files you want to get rid of. HTH Cheers. Bye. Ph. A. -- *Philippe Andersson* Unix System Administrator IBA Particle Therapy | Tel: +32-10-475.983 Fax: +32-10-487.707 eMail: pan@iba-group.com <http://www.iba-worldwide.com> The contents of this e-mail message and any attachments are intended solely for the recipient (s) named above. This communication is intended to be and to remain confidential and may be protected by intellectual property rights. Any use of the information contained herein (including but not limited to, total or partial reproduction, communication or distribution of any form) by persons other than the designated recipient(s) is prohibited. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free. Ion Beam Applications does not accept liability for any such errors. Thank you for your cooperation.
On Wednesday 07 March 2007 03:12, Philippe Andersson wrote:
Gordon Ross wrote: ...
$ find DHbox* -name "*.dat" -o -name "*.pro" -exec rm -f {} \;
would do. Omit the final "-exec..." to first check that it only catches those files you want to get rid of.
If there are very many such files, execing a separate rm for each will be slow. The "|xargs rm" approach only invokes as many rm instances as it takes to handle the number of arguments present. It also frees you from the funky find -exec syntax, which many find confusing.
HTH
Cheers. Bye.
Ph. A.
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wed, Mar 07, 2007 at 08:01:10AM -0800, Randall R Schulz wrote:
On Wednesday 07 March 2007 03:12, Philippe Andersson wrote:
Gordon Ross wrote: ...
$ find DHbox* -name "*.dat" -o -name "*.pro" -exec rm -f {} \;
would do. Omit the final "-exec..." to first check that it only catches those files you want to get rid of.
If there are very many such files, execing a separate rm for each will be slow. The "|xargs rm" approach only invokes as many rm instances as it takes to handle the number of arguments present. It also frees you from the funky find -exec syntax, which many find confusing.
If you pipe into xargs, you probably want to also use find -print0/xargs -0 to protect against filenames containing spaces and other oddities, e.g.: $ find DHbox* -name "*.dat" -o -name "*.pro" -print0 | xargs -0 rm -print0 emits the list of files as a set of null terminated strings, and -0 tells xargs to expect that format and compensate accordingly. As usual, see the find(1) and xargs(1) man pages for more details. -- Steve Beattie SUSE Labs, Novell Inc. <sbeattie@suse.de> http://NxNW.org/~steve/
thanks for reply. trick works :) May I ask you for one more trick? How to remove ALL files from directories EXCEPT '*.pro'? Many thanks Sylvester On Wed, 7 Mar 2007, Sylvester Lykkehus wrote:
Vince Oliver wrote:
Hi All,
How to easily remove some particular files from more than one directory. For example I have directories:
$ ls -l total 12 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox1 drwx------+ 2 ovince None 0 Mar 7 08:30 DHbox10 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox2 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox3 drwx------+ 2 ovince None 0 Mar 6 16:36 DHbox4 drwx------+ 2 ovince None 0 Mar 7 08:31 DHbox5 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox6 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox7 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox8 drwx------+ 2 ovince None 0 Mar 6 16:37 DHbox9
from all these directories I would like to remove JUST files that finish wit suffix = 'pro' and suffix = '.dat' keeping others untouched
thanks oliver
Hi Oliver, find DHbox* -name *.dat | xargs rm should do the trick.
Best regards Sylvester -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Vince Oliver wrote:
thanks for reply. trick works :)
May I ask you for one more trick? How to remove ALL files from directories EXCEPT '*.pro'?
$ find DHbox* -type f -not -name "*.pro" -exec rm -f {} \; Beware that find will recurse any directory below your DHbox*. Make sure that's what you want before typing this command. Omit the -exec part to have a look at the selected file list first. HTH Cheers. Bye. Ph. A. -- *Philippe Andersson* Unix System Administrator IBA Particle Therapy | Tel: +32-10-475.983 Fax: +32-10-487.707 eMail: pan@iba-group.com <http://www.iba-worldwide.com> The contents of this e-mail message and any attachments are intended solely for the recipient (s) named above. This communication is intended to be and to remain confidential and may be protected by intellectual property rights. Any use of the information contained herein (including but not limited to, total or partial reproduction, communication or distribution of any form) by persons other than the designated recipient(s) is prohibited. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free. Ion Beam Applications does not accept liability for any such errors. Thank you for your cooperation.
On 07 March 07 05:29, Vince Oliver wrote: <snip> Vince, please don't top-post. Thanks. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Gordon Ross
-
JB
-
Philippe Andersson
-
Randall R Schulz
-
Steve Beattie
-
Sylvester Lykkehus
-
Vince Oliver