How could I use find
unix utility to find all working copies on the machine? For example, I can use find / -name .svn -type d
command, but it outputs all redundant results (a lot of subfolders), while I need only parent directory of working copy to be shown.
There is related question, but it does not really help in my case: How can I find the root folder of a given subversion working copy
maybe something like this?
#!/bin/bash
if [ -d "$1/.svn" ]; then
echo $1
else
for d in $1/*
do
if [ -d "$d" ]; then
( $0 $d )
fi;
done
fi;
name it, for example - find_svn.sh, make it executable, and call like ./find_svn.sh /var/www
(may need some tweaking to normalize directory name(s), strip trailing slash.. but works for me in this form, when called on some dir without trailing slash).
Update 3 - sorted output of find to ensure .svn comes before hidden files. still might fail for checked-in hidden directories.
Perl can remove the nested paths for you:
find -s . -ipath *.svn | perl -lne's!/\.svn$!!i;$a&&/^$a/||print$a=$_'
In human, this says: for each svn path, ignoring the /.svn
part, if the current path is a child of the last path I printed, don't print it.
example: for the directory structure:
$ find .
.
./1
./1/.svn
./1/1
./1/1/.svn
./2
./2/.svn
./3
this yields
./1
./2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With