Improving Pauls' answer:
The following code:
find /mnt/test -name '*.dav' -exec sh -c 'for filename do
if [[ $(basename "$filename") != C*.dav ]];then
find "$filename" -type f -execdir ~/bin/rnm -y "$filename" -ns '/pd05/_/pd03/_/n/.dav' \;
fi
done' find-sh {} \;
Can be optimized like this (without any find or for loop):
rnm -y -ns '/pd5/_/pd3/_/n/.dav' -ss '^[^C].*\.dav$' -fo -dp -1 /mnt/test
Explanation:
-ss: Search string (regex). The regex used above searches for files that end with .dav and do not start with C.
-fo: File only mode.
-dp: Depth. -1 means unlimited depth i.e go to all subdirectories.
-ns: Name string (new name)
/pd<digit>/: A name string rule that implies different levels of parent directory names: 0 is the immediate parent, 1 is above that and so forth.
/n/: Another name string rule that implies file name without extension. /n/.dav could be replaced with /fn/ (full name).
-y: Confirm (--yes) for all.
\should be replaced by/? If you are, please consider merging your accounts. – Chris Davies Jan 01 '17 at 21:47