如何在SHELL脚本中查找大于500GB的文件

时间:2016-07-18 04:04:26

标签: shell putty

我尝试使用shell脚本在putty中搜索一些超过80天的文件。文件夹大小大于100GB。此命令提供以下异常

        find /data/local_0/ -type f -name "*.txt" -mtime +80

异常:“为数据类型定义的值太大”

2 个答案:

答案 0 :(得分:0)

您可以使用stat命令了解有关文件的所有信息。为了演示,我编写了一个简单的脚本,它将在给定的目录中找到大小超过500GB的文件。

#!/bin/bash
if [ $# -lt 1 ]; then
   echo "[USAGE] : $0 <path>" 
   exit 1
fi
echo "Files having size more than 500GB"
count=0
for i in $1/*
do
     #get the size, it will be in byte nd convert it to GB
     size=$(stat -c %s $i)
     size=`expr $size / 1024 \* 1024`;
     if [ $size -ge 500 ]; then
        count=`expr $count + 1`
        echo ">>> $i"
     fi
done

if [ $count -eq 0 ] ; then
     echo "No files with size more than 500"
fi

exit 0

您可以扩展它以递归遍历所有目录[使用ls -R获取文件]

答案 1 :(得分:0)

find /data/local_0 -mount -type f -name "*.txt" -mtime +80 -size +500G

使用-mount避免其他文件系统上的目录下降。

相关问题