I have a tree of directories from which I would like to recursively dig into, removing source control meta-information from.* In this case, the meta-data is in .svn folders.*
Does anyone have any elegant suggestions on how to do this?*
04-18-2008, 05:13 PM
ChadDavis
bash script question
That's great.* I also saw in Unix Power Tools that you can use xargs to similar effect?
On Fri, Apr 18, 2008 at 10:55 AM, Martin Kraus <lists_mk@wujiman.net> wrote:
On Fri, Apr 18, 2008 at 10:27:30AM -0600, ChadDavis wrote:
> I have a simple bash scripting question.
>
> I have a tree of directories from which I would like to recursively dig
> into, removing source control meta-information from. *In this case, the
> meta-data is in .svn folders.
>
> Does anyone have any elegant suggestions on how to do this?
find . -name .svn -exec rm -r {} ;
04-18-2008, 05:21 PM
Ken Irving
bash script question
On Fri, Apr 18, 2008 at 10:27:30AM -0600, ChadDavis wrote:
> I have a simple bash scripting question.
>
> I have a tree of directories from which I would like to recursively dig into, removing source
> control meta-information from. In this case, the meta-data is in .svn folders.
>
> Does anyone have any elegant suggestions on how to do this?
If you want to remove the .svn/ directories and everything within them, something
like this should work (remove the 'echo' if the output looks ok):
$ cd starting/directory
$ find . -type d -name .svn -exec echo rm -r {} ;
or:
$ find . -type d -name .svn | xargs echo rm -r
I'd recommend EXTREME CAUTION any time you're scripting rm, particularly with
the -r option. Often you may need to do this as root to have rm work without
prompting, and it's easily possible to do real damage by accident...
Ken
--
Ken Irving, fnkci+debianuser@uaf.edu
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
04-18-2008, 05:49 PM
Bob McGowan
bash script question
ChadDavis wrote:
I have a simple bash scripting question.
I have a tree of directories from which I would like to recursively dig
into, removing source control meta-information from. In this case, the
meta-data is in .svn folders.
Does anyone have any elegant suggestions on how to do this?
Others have mentioned the -exec rm... and pipe to xargs rm methods.
These are probably the quickest way to do it. There are tools in
scripting languages like Perl to accomplish similar things, but that
would take more work so is only useful if you need to repeat this
several times and want to be extra careful with error checking.
A comment regarding -exec versus piping to xagrs is in order, though.
The -exec will run the command for each instance found. So if there are
3 directories found, rm will be run 3 times.
xargs tries to build up a command with as many arguments as it can fit
(at least this is the case in this default use). So with the same 3
directories, you'd get one execution of rm with the three directories as
arguments.
For three, this is probably not significant. For hundreds or thousands,
it can be a big advantage to avoid all those fork/exec calls.
--
Bob McGowan
04-18-2008, 05:53 PM
ChadDavis
bash script question
Good to know.* Thank.
On Fri, Apr 18, 2008 at 11:49 AM, Bob McGowan <bob_mcgowan@symantec.com> wrote:
ChadDavis wrote:
I have a simple bash scripting question.
I have a tree of directories from which I would like to recursively dig into, removing source control meta-information from. *In this case, the meta-data is in .svn folders.
Does anyone have any elegant suggestions on how to do this?
Others have mentioned the -exec rm... and pipe to xargs rm methods.
These are probably the quickest way to do it. *There are tools in scripting languages like Perl to accomplish similar things, but that would take more work so is only useful if you need to repeat this several times and want to be extra careful with error checking.
A comment regarding -exec versus piping to xagrs is in order, though.
The -exec will run the command for each instance found. *So if there are 3 directories found, rm will be run 3 times.
xargs tries to build up a command with as many arguments as it can fit (at least this is the case in this default use). *So with the same 3 directories, you'd get one execution of rm with the three directories as arguments.
For three, this is probably not significant. *For hundreds or thousands, it can be a big advantage to avoid all those fork/exec calls.
--
Bob McGowan
04-18-2008, 09:48 PM
Jochen Schulz
bash script question
Ken Irving:
>
> If you want to remove the .svn/ directories and everything within them, something
> like this should work (remove the 'echo' if the output looks ok):
>
> $ cd starting/directory
> $ find . -type d -name .svn -exec echo rm -r {} ;
GNU find also accepts the parameter (or better: operation) -detele so
you don't have to start an rm process for each file or deal with xargs.
That means you can just do (untested):
$ find . -type d -name .svn -delete
J.
--
I worry about people thinking I have lost direction.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
04-18-2008, 11:30 PM
Bob McGowan
bash script question
Jochen Schulz wrote:
Ken Irving:
If you want to remove the .svn/ directories and everything within them, something
like this should work (remove the 'echo' if the output looks ok):
$ cd starting/directory
$ find . -type d -name .svn -exec echo rm -r {} ;
GNU find also accepts the parameter (or better: operation) -detele so
you don't have to start an rm process for each file or deal with xargs.
That means you can just do (untested):
$ find . -type d -name .svn -delete
J.
Sorry to say, this is not so:
mkdir -p xxx/yyy
cp some files xxx
cp some files xxx/yyy
find xxx -type d -delete
find: cannot delete xxx/yyy: Directory not empty
find: cannot delete xxx: Directory not empty
I think, because you restricted the search to directories, it tries to
delete the directories, which still have files because the 'find'
ignored them.
--
Bob McGowan
04-19-2008, 12:25 AM
Tzafrir Cohen
bash script question
On Fri, Apr 18, 2008 at 10:27:30AM -0600, ChadDavis wrote:
> I have a simple bash scripting question.
>
> I have a tree of directories from which I would like to recursively dig
> into, removing source control meta-information from. In this case, the
> meta-data is in .svn folders.
I just wonder if this is supposed to be used where 'svn export' better
be.
--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
04-19-2008, 02:39 AM
ChadDavis
bash script question
I just wonder if this is supposed to be used where 'svn export' better
be.
No, its the Sysdeo tomcat plugin's export WAR file feature.* it
doesn't, as far as I can tell, have a mechanism for filtering out
things like .svn.
04-19-2008, 08:17 AM
Tzafrir Cohen
bash script question
On Fri, Apr 18, 2008 at 08:39:10PM -0600, ChadDavis wrote:
> >
> > I just wonder if this is supposed to be used where 'svn export' better
> > be.
> >
> >
>
> No, its the Sysdeo tomcat plugin's export WAR file feature. it doesn't, as
> far as I can tell, have a mechanism for filtering out things like .svn.
Another way to cheat here is to use 'rsync -C' (for local copies as
well).
--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org