The post has been edited since I read in a comment that you have 100,000+ such directories.
Do not use any method that includes bash globbing, it will be terribly slow and inefficient. Instead, use this find from the photos directory:
find -regex '\./[0-9]+' -type d -exec mv -n -- {}/photo.jpg {}.jpg \; -empty -delete
I use the -n option for mv so that we do not overwrite existing files. Use it if your version of mv supports it. You can also use the -v option so that mv verbose and you see what happens:
find -regex '\./[0-9]+' -type d -exec mv -nv -- {}/photo.jpg {}.jpg \; -empty -delete
Read the previous command as:
-regex '\./[0-9]+' : find everything in the current directory that has only digits in the name-type d : and it should be a directory-exec mv -n -- {}/photo.jpg {}.jpg \; : move the photo.jpg file in this directory to the parent directory with the name: dirname.jpg-empty : if the directory is empty ...-delete : ... delete it.
After that, you may want to find out which directories have not been deleted (because, for example, it had more files than just the photo.jpg file):
find -regex '\./[0-9]+' -type d
Enjoy it!
source share