How to remove all .svn directories from my application directories

前端 未结 11 2549
臣服心动
臣服心动 2020-12-04 04:26

One of the missions of an export tool I have in my application, is to clean all .svn directories from my application directory tree. I am looking for a recursiv

相关标签:
11条回答
  • 2020-12-04 05:11

    As an important issue, when you want to utilize shell to delete .svn folders You need -depth argument to prevent find command entering the directory that was just deleted and showing error messages like e.g.

    "find: ./.svn: No such file or directory"
    

    As a result, You can use find command like below:

    cd [dir_to_delete_svn_folders]
    find . -depth -name .svn -exec rm -fr {} \;
    
    0 讨论(0)
  • 2020-12-04 05:11

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

    rsync -a --exclude .svn path/to/working/copy path/to/export
    
    0 讨论(0)
  • 2020-12-04 05:12
    find . -name .svn |xargs rm -rf
    
    0 讨论(0)
  • 2020-12-04 05:16

    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.

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

    find . -name .svn | xargs rm -fr
    

    xargs is intelligent enough that it will only pass as many arguments to rm as it can accept. Thus, if you had a million files, it might run rm 1,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}).

    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 -exec forms both call rm for each folder being deleted, so if you had 1,000,000 folders, rm would be invoked 1,000,000 times. This is certainly less than ideal. Newer implementations of rm allow you to conclude the command with a + indicating that rm will accept as many arguments as possible:

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

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

    In addition, there's a -execdir that will execute rm from the directory in which the file was found, rather than at the base directory and a -depth that will start depth first.

    0 讨论(0)
  • 2020-12-04 05:25

    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 export <url>
    
    0 讨论(0)
提交回复
热议问题