I want to rename all nested directories named "foo" to "bar" - I've tried 开发者_如何学Cthe following with no joy:
find */ -name 'foo' | xargs svn move {} 'bar' \;
Thanks
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.
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.
精彩评论