深度阅读

How to delete log files in Linux?

作者
作者
2023年08月22日
更新时间
11.01 分钟
阅读时间
0
阅读量

To delete log files in Linux, you can use the rm command. For example, to delete a log file called my_log.txt, you can use the following command:

rm my_log.txt

If you want to delete all log files in a directory, you can use a wildcard * to match all files with a particular extension. For example, to delete all log files with a .log extension in the current directory, you can use the following command:

rm *.log

Alternatively, you can use the find command to locate and delete log files based on certain criteria, such as the file modification time or the file name. For example, to delete all log files older than 30 days in the /var/log directory, you can use the following command:

find /var/log -type f -mtime +30 -name '*.log' -delete

This will find all files ( -type f ) with a modification time older than 30 days ( -mtime +30) and a name that matches the pattern *.log, then delete them ( -delete). Note that the find command can be a powerful tool, so exercise caution when using it to avoid accidentally deleting important files.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。