Warning: Please make a backup first, as this can do irreversable damage.
Go to your uploads directory:
cd /path/to/directory
cp -r uploads uploads.backup
Flatten the files in uploads directory:
find * -type f -exec bash -c 'file=${1#./}; echo mv "$file" "${file//\//_}"' _ '{}' \;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017/12/some-image-150x150.jpg ---> 2017_12_some-image-150x150.jpg
2017/12/some-image-360x240.jpg ---> 2017_12_some-image-360x240.jpg
2017/12/some-image-720x900.jpg ---> 2017_12_some-image-720x900.jpg
2017/12/some-image.jpg ---> 2017_12_some-image.jpg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Delete the "echo" after you try, this only outputs what's gonna happen !
Remove empty directories:
find * -depth -type d -exec echo rmdir '{}' \;
Delete smaller files with name pattern: some_file[NUMBER]x[NUMBER].jpg:
find * -type f -name '*[0-9]x[0-9]*.jpg' -delete;