I have decades worth of family photos and videos that are organized and labeled within a directory tree containing thousands of directories. The file paths, in general, all look like:
an example could be:
/my_giant_pictures_dir/2016/07_27_Roadtrip to Antarctica/IMG_00001.jpg
note that the "event," or deepest directories may contain .jpg, .mp4, and .mts files.
My problem with this convention is that I end up with many deepest media-containing directories that, because they are organized first by date, contain only one or a few files. (Days where only one picture was taken, for example). This makes looking through, say, all the pictures taken during a three month period, rather tedious.
I would like to restructure all of this media by keeping everything in chronological order as it is, but by eliminating all of the intermediate subdirectories after the year. I would like to do this by prepending every media filename with its parent directory's "month_day_event" name, for example:
/Pictures/2016/07_27_Roadtrip to Antarctica/IMG_00001.jpg
...I would rather have:
/Pictures/2016/07_27_Roadtrip to Antarctica_IMG_00001.jpg
Is there a bash command that would do this for every .jpg, .mp4, and .mts file in my entire pictures directory, then after the filename prepend, move them out of their parent directory and into the next highest directory, which in every case is the year directory?
And maybe it is asking too much, but could it also delete the then empty subdirectories that are contained within the year directories? I don't mind running multiple commands if necessary because, either way, your answer will be saving me countless hours.
Thank you very much in advance!