Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recursive directory svn move shell script

Tags:

bash

svn

I want to rename all nested directories named "foo" to "bar" - I've tried the following with no joy:

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

Thanks

like image 511
Dr. Frankenstein Avatar asked Dec 15 '25 11:12

Dr. Frankenstein


2 Answers

That will attempt to move each foo to pwd/bar and passes svn move too many arguments. Here's what I would do:

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

You can remove the echo to have it actually perform the operation. The above works under the assumption that you don't have spaces in your filenames.

like image 74
Kaleb Pederson Avatar answered Dec 17 '25 02:12

Kaleb Pederson


You could use bash to visit manually the directory tree using a 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

This code doesn't have any infinite loops detection, but should work in simple cases.

like image 45
marco Avatar answered Dec 17 '25 00:12

marco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!