Coder Perfect

How can I get rid of all.svn folders in my application directories?


Cleaning all.svn folders from my application directory tree is one of the tasks of an export tool I have in my application. In the Linux shell, I’m looking for a recursive command that would scan the entire tree and delete the.svn files.

I’m not using export because this script will be used for names of files and directories that aren’t connected to SVN. I attempted something along these lines:

find . -name .svn | rm -fr

It didn’t work…

Asked by Itay Moav -Malimovka

Solution #1

Try this:

find . -name .svn -exec rm -rf '{}' \;

Before I execute a command like that, I like to run the following:

find . -name .svn -exec ls '{}' \;

Answered by Greg

Solution #2

Rm receives a list of newline separated file names (and paths) from what you wrote, but it has no idea what to do with it. Only command line parameters are expected.

Adding xargs makes what you had work: xargs takes input, normally separated by newlines, and inserts it on the command line.

find . -name .svn | xargs rm -fr

xargs is sophisticated enough to only pass rm as many arguments as it can handle. If your shell could accept 65,002 arguments on the command line (65k files + 1 for rm + 1 for -fr), it could perform rm 1,000,000/65,000 times if you had a million files.

The following also works, as others have pointed out:

find . -name .svn -exec rm -rf {} \;
find . -depth -name .svn -exec rm -fr {} \;
find . -type d -name .svn -print0|xargs -0 rm -rf

For each folder being removed, the first two -exec forms both call rm, so if you had 1,000,000 folders, rm would be called 1,000,000 times. This is a far cry from ideal. In newer versions of rm, you can finish the command with a + to indicate that rm will accept as many arguments as possible:

find . -name .svn -exec rm -rf {} +

The most recent version of find/xargs uses print0, which causes find to generate output with a terminator of 0 rather than a newline. Because POSIX systems allow any character other than 0 in the filename, this is the safest technique to ensure that the arguments to rm or the application being executed are correctly supplied.

There’s also a -execdir option, which will run rm from the directory where the file was discovered rather than the base directory, and a -depth option, which will run depth first.

Answered by Kaleb Pederson

Solution #3

There’s no need for pipes, xargs, or exec:

find . -name .svn -delete

Edit: Just kidding, -delete appears to call unlinkat() behind the scenes, thus it works similarly to unlink or rmdir and refuses to operate on directories containing files.

Answered by A B

Solution #4

There have already been numerous responses to the question of how to delete the.svn-directory. But I’d want to point out that if you do an export instead of a checkout, you can avoid these folders from the start:

svn export <url>

Answered by Mnementh

Solution #5

If you don’t like seeing a lot of things, this isn’t the place for you.

find: `./.svn': No such file or directory

warnings, then use the -depth switch:

find . -depth -name .svn -exec rm -fr {} \;

Answered by lazy1

Post is based on