Linux 如何从我的应用程序目录中删除所有 .svn 目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1294590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:37:44  来源:igfitidea点击:

How to remove all .svn directories from my application directories

linuxshell

提问by Itay Moav -Malimovka

One of the missions of an export tool I have in my application, is to clean all .svndirectories from my application directory tree. I am looking for a recursive command in the Linux shell that will traverse the entire tree and delete the .svnfiles.

我的应用程序中的导出工具的任务之一是清除.svn应用程序目录树中的所有目录。我正在 Linux shell 中寻找一个递归命令,该命令将遍历整个树并删除.svn文件。

I am not using export, as this script will be used for some other file/directory names which are not related to SVN. I tried something like:

我没有使用导出,因为此脚本将用于其他一些与 SVN 无关的文件/目录名称。我试过类似的东西:

find . -name .svn | rm -fr

It didn't work...

它没有用...

采纳答案by Greg

Try this:

尝试这个:

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

Before running a command like that, I often like to run this first:

在运行这样的命令之前,我通常喜欢先运行:

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

回答by soulmerge

You almost had it. If you want to pass the output of a command as parameters to another one, you'll need to use xargs. Adding -print0makes sure the script can handle paths with whitespace:

你几乎拥有它。如果要将命令的输出作为参数传递给另一个命令,则需要使用 xargs。添加-print0确保脚本可以处理带有空格的路径:

find . -type d -name .svn -print0|xargs -0 rm -rf

回答by Edward Dale

Try this:

尝试这个:

find . -name .svn -exec rm -v {} \;

Read more about the find command at developerWorks.

developerWorks 上阅读有关 find 命令的更多信息。

回答by lazy1

If you don't like to see a lot of

如果你不喜欢看很多

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

warnings, then use the -depthswitch:

警告,然后使用-depth开关:

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

回答by Itay Moav -Malimovka

find . -name .svn |xargs rm -rf

回答by pimlottc

Alternatively, if you want to export a copy without modifying the working copy, you can use rsync:

或者,如果您想在不修改工作副本的情况下导出副本,则可以使用 rsync:

rsync -a --exclude .svn path/to/working/copy path/to/export

回答by Kaleb Pederson

What you wrote sends a list of newline separated file names (and paths) to rm, but rm doesn't know what to do with that input. It's only expecting command line parameters.

您编写的内容将换行符分隔的文件名(和路径)列表发送到rm,但 rm 不知道如何处理该输入。它只需要命令行参数。

xargstakes input, usually separated by newlines, and places them on the command line, so adding xargs makes what you had work:

xargs接受输入,通常用换行符分隔,并将它们放在命令行上,因此添加 xargs 使您的工作正常:

find . -name .svn | xargs rm -fr

xargsis intelligent enough that it will only pass as many arguments to rmas it can accept. Thus, if you had a million files, it might run rm1,000,000/65,000 times (if your shell could accept 65,002 arguments on the command line {65k files + 1 for rm + 1 for -fr}).

xargs足够智能,它只会向rm它传递尽可能多的参数。因此,如果您有一百万个文件,它可能会运行rm1,000,000/65,000 次(如果您的 shell 可以在命令行上接受 65,002 个参数 {65k files + 1 for rm + 1 for -fr})。

As persons have adeptly pointed out, the following also work:

正如人们巧妙地指出的那样,以下方法也有效:

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

The first two -execforms both call rmfor each folder being deleted, so if you had 1,000,000 folders, rmwould be invoked 1,000,000 times. This is certainly less than ideal. Newer implementations of rmallow you to conclude the command with a +indicating that rmwill accept as many arguments as possible:

前两种-exec形式都要求rm删除每个文件夹,因此如果您有 1,000,000 个文件夹,rm将被调用 1,000,000 次。这当然不太理想。的较新实现rm允许您使用一个+指示来结束命令,该指示rm将接受尽可能多的参数:

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

The last find/xargs version uses print0, which makes find generate output that uses \0as a terminator rather than a newline. Since POSIX systems allow any character but \0in the filename, this is truly the safest way to make sure that the arguments are correctly passed to rmor the application being executed.

最后一个 find/xargs 版本使用 print0,这使得 find 生成\0用作终止符而不是换行符的输出。由于 POSIX 系统允许\0文件名中的任何字符,因此这确实是确保参数正确传递给rm或正在执行的应用程序的最安全方法。

In addition, there's a -execdirthat will execute rmfrom the directory in which the file was found, rather than at the base directory and a -depththat will start depth first.

此外,还有一个-execdir将从rm找到文件的目录执行,而不是在基目录中执行,-depth并且将首先从深度开始。

回答by Nathan Taylor

In Windows, you can use the following registry script to add "Delete SVN Folders" to your right click context menu. Run it on any directory containing those pesky files.

在 Windows 中,您可以使用以下注册表脚本将“删除 SVN 文件夹”添加到右键单击上下文菜单中。在包含这些讨厌文件的任何目录上运行它。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

回答by A B

No need for pipes, xargs, exec, or anything:

不需要管道、xargs、exec 或任何东西:

find . -name .svn -delete

Edit:Just kidding, evidently -deletecalls unlinkat()under the hood, so it behaves like unlinkor rmdirand will refuse to operate on directories containing files.

编辑:开个玩笑,显然是在幕后-delete调用unlinkat(),因此它的行为类似于unlinkorrmdir并且将拒绝对包含文件的目录进行操作。

回答by Mnementh

There are already many answers provided for deleting the .svn-directory. But I want to add, that you can avoid these directories from the beginning, if you do an export instead of a checkout:

已经提供了许多删除 .svn 目录的答案。但我想补充一点,如果您进行导出而不是结帐,则可以从一开始就避免使用这些目录:

svn export <url>