我正在尝试将大型目录复制到S3,并希望将大于5 GB的文件分开。如果到目前为止做了以下:
cd / source /目录/ dsize = $(du -sh) bigfile = $(找-size + 5G </跨度> -exec du -sh锟笨{} \;) smallfiles = $(找-size - 5G </跨度> -exec du -sh {} \;)if [“$ smallfiles”!=“$ bigfiles”]然后对于$ smallfiles中的sfile做cp -ravf $ sfile / destination / for / smallfiles /DONE 否则
这应该工作
cd /source/directory/ find . -size -5G | xargs -i{} cp -ravf {} /destination/for/smallfiles/ find . -size +5G | xargs -i{} cp -ravf {} /destination/for/bigfiles/
去掉 -exec du -sh {} \; 从您的命令,因为它也添加文件的大小。使用 -type f 仅选择以下文件:
-exec du -sh {} \;
-type f
bigfile=$(find . -type f -size +5G)
感谢您的支持,我做了排序方法,我尝试了If条件,但每次都失败了。 所以我喜欢这样:
sd=$(du -d1 | awk '$1<5000000''{print $2}') for d in $sd do cp -rvaf $d /destination/for/smallfiles/ done echo "Small directories has been copied to smallfiles/" bd=$(du -d1 | awk '$1>5000000''{print $2}') echo "Copying Bigfiles.............." for d in $bd do cp -rvaf $d /destination/for/bigfiles/ done
如果你有更好的解决方案,最受欢迎....