The trick is to use the mindepth and maxdepth argument
Here is the command that I used:
`find folder -mindepth 2 -maxdepth 2 -type d -exec sh -c 'mv "${0}" "${0%?}"' {} \;`
Also note that I used ${0$?} instead of the double ?? that you used. One way to debug find problems like these is to apend your action with echo. So in the above example you would place an echo before the mv command.
$ find .
.
./folder
./folder/folder1
./folder/folder1/foldera
./folder/folder2
./folder/folder2/folderb
./folder/folder3
./folder/folder3/folderc
$ find folder -mindepth 2 -maxdepth 2 -type d -exec sh -c 'mv "${0}" "${0%?}"' {} \;
$ find .
.
./folder
./folder/folder1
./folder/folder1/folder
./folder/folder2
./folder/folder2/folder
./folder/folder3
./folder/folder3/folder
Incidentally, I could have used find .
or find folder
since I was in the parent directory of folder. However, if you use find .
for your exec command, then every subdirectory in the parent directory would have been converted. It is usually better to explicitly list out the directory when you are doing moves, deletes, etc to avoid unexpected results.