[英]Bash Script - Need to remove files from a directory till the Directory size is Less than 8 TB
Below is the high level scenario for which I need to create a bash script. 以下是我需要为其创建bash脚本的高级方案。
- /sasdata2/SAS-USERS/PBU/
- /sasdata2/SAS-USERS/PBU/
Below is a script I am using, but it is going in an infinite loop on the while statement. 下面是我正在使用的脚本,但是它在while语句中处于无限循环中。 Need your help in making a script for the above scenario.
在为上述情况制作脚本时需要您的帮助。
while [ "$(du -shb /sasdata2/SAS-USERS/PBU | awk '{print $1}')" -gt 900 ]
do
find /sasdata2/SAS-USERS/PBU -maxdepth 0 -type f -printf '%T@\t%p\n' | \
sort -n | head -n 25 | cut -d $'\t' -f 2- | xargs -d '\n' rm -f
done
I think your while condition is wrong. 我认为您的条件不对。 du -b will give you bytes, why comparing to 900?
du -b会给您字节,为什么要加上900?
Beside, Why do you need a loop on du and delete arbitrary 25 files? 另外,为什么需要在du上循环并删除任意25个文件? calculate with du how many bytes you are over 8TB, then ls -ltr and in a loop delete files and sum their size until you reach the over bytes
用du计算您超过8TB的字节数,然后使用ls -ltr并循环删除文件并求和它们的大小,直到达到超出字节数为止
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.