如何删除系统日志和 tmp 目录下的临时文件

删除系统日志
查看系统日志所占空间

[user@localhost ~]$ sudo du --human-readable --max-depth=1 /var/log/
[user@localhost ~]$ sudo journalctl --disk-usage

What is:

[user@localhost ~]$ whatis du
du (1)               - estimate file space usage
[user@localhost ~]$ whatis journalctl
journalctl (1)       - Query the systemd journal
删除系统日志

sudo journalctl --vacuum-time=1weeks

journalctl 手册

--disk-usage
           Shows the current disk usage of all journal files. This shows the
           sum of the disk usage of all archived and active journal files.
           
--vacuum-size=, --vacuum-time=, --vacuum-files=
           Removes the oldest archived journal files until the disk space they
           use falls below the specified size (specified with the usual "K",
           "M", "G" and "T" suffixes), or all archived journal files contain
           no data older than the specified timespan (specified with the usual
           "s", "m", "h", "days", "months", "weeks" and "years" suffixes), or
           no more than the specified number of separate journal files remain.
           Note that running --vacuum-size= has only an indirect effect on the
           output shown by --disk-usage, as the latter includes active journal
           files, while the vacuuming operation only operates on archived
           journal files. Similarly, --vacuum-files= might not actually reduce
           the number of journal files to below the specified number, as it
           will not remove active journal files.  --vacuum-size=,
           --vacuum-time= and --vacuum-files= may be combined in a single
           invocation to enforce any combination of a size, a time and a
           number of files limit on the archived journal files. Specifying any
           of these three parameters as zero is equivalent to not enforcing
           the specific limit, and is thus redundant.
       
删除临时文件缓存

使用 tmpwatch
sudo dnf install tmpwatch
手册

DESCRIPTION
       tmpwatch  recursively  removes  files  which haven't been accessed for a given time.  Normally, it's used to clean up directories which are
       used for temporary holding space such as /tmp.
       ...
       By  default,  tmpwatch dates files by their atime (access time), ...
       ...
       ... m for minutes, h for hours, d for days.  If  no  suffix
       is specified, time is in hours.

删除最近 3 小时没有访问的临时文件

[user@localhost ~]$ sudo /usr/sbin/tmpwatch -afv 3h /tmp

[1] http://crx.xmspace.net/linux_tmp_del.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值