There are two immediate reasons that your attempt isn't working:
- You aren't using the variable
d
that you are using to iterate over the directory.
- Your iteration glob doesn't include the final files, only the sub-directories.
EDIT: Here, first, is an improved simpler answer that doesn't require performing any checks because the initial glob selects only the pdb files.
for one-path in root-directory/*/*.pdb
do
mv "$one-path" "$(dirname $one-path)/test.pdb"
done
My original inferior answer follows, along with some comments, using the bash shell and two core utilities (basename
and dirname
):
for one-path in root-directory/*/*
do
[[ "$(basename "$one-path")" =~ pdb$ ]] \
&& mv "$one-path" "$(dirname $one-path)/test.pdb"
done
root-directory
is whatever absolute path-spec you are using.
root-directory/*/*
is a glob that will return actual files in your defined case, not just sub-directories.
=~
is a bash shell extension to allow limited regular expression testing, in this case for a string ending with pdb
&&
is a logical AND; it's a common idiom replacement for a simple if
...then
(don't forget the back-slash continuation symbol on the prior line).