Recursive directory svn move shell script

I want to rename all sub directories named "foo" to "bar". I tried the following without joy:

find */ -name 'foo' | xargs svn move {} 'bar' \;

thank

+3
source share
2 answers

This will try to move each footo pwd/ bar and pass svn movetoo many arguments. Here is what I will do:

find . -depth -type d -name 'foo' -print | while read ; do echo svn mv $REPLY `dirname $REPLY`/bar ; done 

You can delete echoto complete the operation. The above works under the assumption that you have no spaces in the file names.

+1
source

You can use bash to manually view the directory tree using post-order walk:

#!/bin/bash

visit() {
local file
for file in $1/*; do 
    if [ -d "$file" ]; then
        visit "$file";
        if [[ $file =~ /foo$ ]]; then
            svn move $file ${file%foo}bar;
        fi                  
    fi
done
}

if [ $# -ne 1 ]; then
exit
fi

visit $1

, .

+1

Source: https://habr.com/ru/post/1750132/


All Articles