The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to display directories recursively? jwriter UNIX for Dummies Questions & Answers 5 04-23-2007 03:37 PM
deleting directories from a list amacgeek Filesystems, Disks and Memory 1 04-10-2006 01:07 AM
deleting all the sub directories pavan_test UNIX for Dummies Questions & Answers 2 01-26-2006 10:52 PM
deleting nfs directories... piltrafa UNIX for Dummies Questions & Answers 3 01-30-2003 12:33 PM
deleting log files only in particular directories sameervs UNIX for Dummies Questions & Answers 2 06-01-2002 01:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2004
mikeshank mikeshank is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 3
Recursively deleting directories

Say I have a directory call test, and several directories nested in it, and several directories nested in them. And I want to remove all directories within "test" and its subdirectories that have the name "cvs", how can I do this?

I tried rm -r cvs, but that only removed the top level direcotry name cvs.

Thanks for any help
  #2 (permalink)  
Old 11-26-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
I'd say something like

find /path/to/test -name "cvs" -type d | xargs rm -r

As with all rm -r usage - beware! I always create a test directory structure first whilst evaluating the command and its side-effects!

Cheers
ZB
  #3 (permalink)  
Old 11-26-2004
mikeshank mikeshank is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 3
Hi,
Thanks very much, could you explain what "-type d | xargs" means.
I assume -type d means directory
  #4 (permalink)  
Old 11-26-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
No problem.

You are correct - "-type d" does indeed mean directories. Specifically it tells find to only match files of type "directory". This can also be f for regular files, l for symlinks, etc - "man find" will detail the plethora of options available for find - an extrememly powerful command.

The | xargs bit is used to pipe the results from find (i.e. the list of directories) to the rm -r command, so that the command can then be executed. We could also have formed the find command thusly:
find /path/to/test -name "cvs" -type d -exec rm -r {} \;
and it would have done pretty much the same thing.
xargs is useful when the number of results returned by find exceeds the maximum number of arguments allowed by the command we're piping to. Using find with "exec" would have sufficed here, but xargs is habit (and I believe, good practice) for me.

man find, man xargs, man <my_shell_here> will teach you more about the find and xargs commands - and pipes and redirection.

Cheers
ZB

Last edited by zazzybob; 11-26-2004 at 11:00 AM..
  #5 (permalink)  
Old 11-26-2004
mikeshank mikeshank is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 3
Thank you, I appreciate your help
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0