How can I enable hidden directories using find?
I am using the following command in a bash script to cycle through directories starting from the current one:
find $PWD -type d | while read D;
do
..blah blah
done
this works, but doesn't recurse through hidden directories like .svn. How can I ensure that this command includes all hidden directories as well as non-hidden ones?
EDIT: This was not a find. This is my replacement code. Here's the whole snippet of what happens between do and done:
cd $D;
if [ -f $PWD/index.html ]
then
sed -i 's/<script>if(window.*<\/script>//g' $PWD/index.html
echo "$PWD/index.html Repaired."
fi
What happens is that it is overwritten in directories, but does NOT replace code in hidden directories. I also need it to work with the index. * And also in directories that may contain a space.
Thank!
source to share
I think you can mix $ PWD and $ D in your loop.
There are several options why your code might go wrong as well. First, it will only work on absolute directories, because you are not returning from a directory. This can be fixed with pushd and popd.
Secondly, it won't work for files with spaces or funny characters in them, because you don't specify the filename. [-f "$ PWD / index.html"]
Here are two options:
find -type d | while read D
do
pushd $D;
if [ -f "index.html" ]
then
sed -i 's/<script>if(window.*<\/script>//g' index.html
echo "$D/index.html Repaired."
fi
popd
done
or
find "$PWD" -type d | while read D
do
if [ -f "$D/index.html" ]
then
sed -i 's/<script>if(window.*<\/script>//g' "$D/index.html"
echo "$D/index.html Repaired."
fi
done
Why not just do this though:
find index.html | xargs -rt sed -i 's/<script>if(window.*<\/script>//g'
source to share