LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-04-2006, 10:08 AM   #1
allelopath
Member
 
Registered: Jan 2003
Location: New Mexico
Distribution: Ubuntu 18.04.3 LTS
Posts: 539

Rep: Reputation: 30
rm dir recursively


I have a directory structure something like this:

dir1
..cvs
..dir1a
....cvs
....dir1b
......cvs
dir2
..cvs
..dir2a
....cvs

i want to remove all directories names 'cvs'
What is the command to do this?

The following:
rm -d
or
rm -r
aren't quite right.
 
Old 01-04-2006, 10:15 AM   #2
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
I think shell script can do it.
 
Old 01-04-2006, 11:38 AM   #3
morrolan
Member
 
Registered: Sep 2003
Location: Manchester UK
Posts: 264

Rep: Reputation: 30
A shell script is the best way.

I don't know bash syntax well enough to write it for you from memory, but you want something that:

Searches through the structure recursively looking for directories called CVS and erases them.

Grep is going to be your best friend for this. "man grep", as it has a recursive option, meaning you can ls a folder recursively.

Don't quote me on this, but something like (ls -a $dir1 | grep -r cvs | rm)

That could be complete bull**** code for all I know, but you get the rough idea.

All you have to figure out is how to then delete them all!

BTW, how many CVS directories are we talking about here?

Last edited by morrolan; 01-04-2006 at 11:40 AM.
 
Old 01-04-2006, 12:14 PM   #4
allelopath
Member
 
Registered: Jan 2003
Location: New Mexico
Distribution: Ubuntu 18.04.3 LTS
Posts: 539

Original Poster
Rep: Reputation: 30
20

>>BTW, how many CVS directories are we talking about here?
20 or so.
does it matter whether it is 2 or 200?
 
Old 01-04-2006, 12:36 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Maybe something like this.
Be careful with the rm -rf command:
Code:
find . -type d -name 'cvs' -exec rm -rf {} \;
 
Old 01-06-2006, 11:11 AM   #6
allelopath
Member
 
Registered: Jan 2003
Location: New Mexico
Distribution: Ubuntu 18.04.3 LTS
Posts: 539

Original Poster
Rep: Reputation: 30
thanks, this works.
i tested it first by doing this:

find . -type d -name 'cvs' -exec ls -R {} \;

and then using the real command on a 'fake' directory structure

Quote:
Originally Posted by homey
Maybe something like this.
Be careful with the rm -rf command:
Code:
find . -type d -name 'cvs' -exec rm -rf {} \;
 
Old 01-06-2006, 11:37 AM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
i tested it first by doing this:
Good job! glad it works
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Share configuratin dir (.dir) for 3 accounts on local computer LiNuXkOlOnIe Linux - Software 5 01-08-2006 03:36 AM
lowercase recursively cubax Linux - General 6 05-29-2005 04:20 PM
how to do yes to all when deleting a dir recursively dr_zayus69 Linux - Newbie 6 12-02-2004 02:42 AM
howto make a dir shared that is not in my home dir Schmurff Linux - Newbie 2 06-19-2004 07:54 PM
krecipes and ./configure -with-qt-dir=DIR disco rugby Linux - Software 4 06-13-2004 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration