Here is what I have run into over the last few days in my spare time. With the code:
Code:
#!/bin/bash
for d in $(find . -type d -name "\$SBV\$")
do
for f in "$(find . -maxdepth 1 -type f)"
do
mv "$f" "${d}"/..
done
rmdir "$d"
done
I end up with the following:
Code:
mv: cannot move `./orig.sh' to `./Virtual/..': No such file or directory
rmdir: failed to remove `./Virtual': No such file or directory
mv: cannot move `./orig.sh' to `Server/..': No such file or directory
rmdir: failed to remove `Server': No such file or directory
mv: cannot move `./orig.sh' to `2005/Linux/..': No such file or directory
rmdir: failed to remove `2005/Linux': No such file or directory
mv: cannot move `./orig.sh' to `Additions/..': No such file or directory
rmdir: failed to remove `Additions': No such file or directory
mv: cannot move `./orig.sh' to `for/..': No such file or directory
rmdir: failed to remove `for': No such file or directory
mv: cannot move `./orig.sh' to `Virtual/..': No such file or directory
rmdir: failed to remove `Virtual': No such file or directory
mv: cannot move `./orig.sh' to `Server/$SBV$/..': No such file or directory
rmdir: failed to remove `Server/$SBV$': No such file or directory
mv: cannot move `./orig.sh' to `./Virtual/..': No such file or directory
rmdir: failed to remove `./Virtual': No such file or directory
mv: cannot move `./orig.sh' to `Server/..': No such file or directory
rmdir: failed to remove `Server': No such file or directory
mv: cannot move `./orig.sh' to `2005/$SBV$/..': No such file or directory
rmdir: failed to remove `2005/$SBV$': No such file or directory
for the script named orig.sh located in tessst/ with a directory named Virtual Server 2005 as a subdirectory.
I have tried an absolute path such as ~/Documents/Data/SBVBakCorrections/tessst for
Code:
for f in "$(find ~/ABUNCHOFDIRECTORIES/tessst -maxdepth 1 -type f)"
and receive the following:
Code:
mv: cannot move `/ABUNCHOFDIRECTORIES/tessst/orig.sh' to `2005/$SBV$/..': No such file or directory
rmdir: failed to remove `2005/$SBV$': No such file or directory
I was able to do a great deal of manual cleanups via the following three commands:
Code:
for i in $(find . -type d -name "\$SBV\$"); do mv "$i"/* "$i"/..; done
for i in $(find . -type d -name "\$SBV\$"); do mv "$i"/.* "$i"/..; done
for i in $(find . -type d -name "\$SBV\$"); do rmdir "$i"; done
The only down side is that there are soooo many directories and subdirectories that have spaces in them that it would take weeks of spare time just fishing through them to get them all. It would be much better if there was a way to recursively follow through the directory structure from a given starting point and find all $SBV$ folder, move the files in this folder up one level, then remove the $SBV$ folder in one swath. I have also looked into using the find -print0 w/ xargs argument but have been unable to get the /bin/mv to accept the piped in info.
Code:
find . -name "\$SBV\$" -type d -print0 | xargs -0 /bin/mv *.* ..
As I get the output:
Code:
/bin/mv: cannot move `..' to `./Virtual Server 2005/$SBV$/..': Device or resource busy
Once again, any input would be greatly appreciated and I will continue in my spare time to continue reading, testing and banging my head on the desk...