如何在 Centos7 中使用 python 脚本或 bash 脚本列出所有早于 "X" 小时的文件?
很多谢谢!
你可以使用 GNU find 命令:
find [path] -mmin +[minutes]
示例:查找 2 小时内/超过 2 小时的所有文件:
find / -mmin +120
您可以使用find
命令:
find <path> <conditions> <actions>
文件类型条件:
-type f # File
-type d # Directory
-type l # Symlink
访问时间条件 :
-atime 0 # Last accessed between now and 24 hours ago
-atime +0 # Accessed more than 24 hours ago
-atime 1 # Accessed between 24 and 48 hours ago
-atime +1 # Accessed more than 48 hours ago
-atime -1 # Accessed less than 24 hours ago (same a 0)
-ctime -6h30m # File status changed within the last 6 hours and 30 minutes
-mtime +1w # Last modified more than 1 week ago
行动:
-exec rm {} ;
-print
-delete
你也可以处理大小:
-size 8 # Exactly 8 512-bit blocks
-size -128c # Smaller than 128 bytes
-size 1440k # Exactly 1440KiB
-size +10M # Larger than 10MiB
-size +2G # Larger than 2GiB
例子:
find . -type f ctime -6h30m # File status changed within the last 6 hours and 30 minutes
find . -type f -mtime +29 # find files modified more than 30 days ago