Linux 查找大文件 & 清理日志文件

Linux 查找大文件 & 清理日志文件1、linux查找大日志文件并且删除clean-log.sh脚本如下:#!

大家好,欢迎来到IT知识分享网。

1、linux查找大日志文件并且删除

Linux 查找大文件 & 清理日志文件

clean-log.sh

脚本如下:

#!/bin/bash # Specify the log folder path log_folder="/path/to/log/folder" # Specify the minimum size threshold for log files (in Megabytes) threshold=100 # Find log files larger than the threshold size find "$log_folder" -type f -name "*.log" -size +${threshold}M -exec du -sh {} \; # Prompt user confirmation before deleting log files while true; do read -p "Do you want to delete these log files? (yes/no): " yn case $yn in [Yy]* ) find "$log_folder" -type f -name "*.log" -size +${threshold}M -exec rm -f {} \;; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done

请先将/path/to/log/folder替换为您实际的log文件夹路径,并指定一个您认为较大的文件阈值(以兆字节为单位)。然后,保存上述脚本到一个文件(例如find_and_delete_logs.sh),并赋予它执行权限:

chmod +x find_and_delete_logs.sh

最后,在终端中运行脚本:

./find_and_delete_logs.sh

脚本会列出大于指定阈值的log文件,并在您确认后删除这些文件。请确保在运行脚本之前备份重要的log数据。

2、linux查找大文件

Linux 查找大文件 & 清理日志文件

find-max-file.sh

脚本如下:

#!/bin/bash # Specify the log folder path log_folder=$1 # Specify the minimum size threshold for log files (in Megabytes) threshold=30 # Find files larger than the threshold size find "$log_folder" -type f -size +${threshold}M -exec du -sh {} \; | sort -n -r

入参传入 文件夹路径

大于30M的文件会被检索出来 然后按照数字大小逆序排序

3、脚本运行效果

Linux 查找大文件 & 清理日志文件

find-max-file.sh 结果

Linux 查找大文件 & 清理日志文件

clean-log.sh

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/52660.html

(0)
上一篇 2024-08-09 20:15
下一篇 2024-08-09 22:33

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信