Warning: 请先备份,因为这会造成不可挽回的损害。
转到上载目录:
cd /path/to/directory
cp -r uploads uploads.backup
展平上载目录中的文件:
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 !
删除空目录:
find * -depth -type d -exec echo rmdir \'{}\' \\;
删除具有名称模式的较小文件:some\\u file[编号]x[编号]。jpg:
find * -type f -name \'*[0-9]x[0-9]*.jpg\' -delete;