1.什么是临时文件
下载和安装'卸载软件、打开电子邮件和即时消息程序中的文件或传输文件时创建。通常,创建临时文件的程序会在完成时将其删除,但有时候这些文件会被保留。
一段时间后,这些废弃的临时文件(若长时间不清理会相当大)可能会占去大量的硬盘空间、累积硬盘磁盘碎片并降低系统性能。删除这些文件是安全的。
2.linux中的临时文件管理
命令如下:
su - #切换超级用户
cd /usr/lib/tmpfiles.d/ #切换目录
vim westos.conf #编辑配置文件
d /mnt/westos 1777 root root 10s #设定
watch -n1 ls -lR /mnt/ #监控
另开启一个shell
systemd-tmpfiles --create /usr/lib/tmpfiles.d/*
touch /mnt/westos/file #创建一个临时文件
systemd-tmpfiles --clean /usr/lib/tmpfiles.d/* #尝试清除该临时文件
过10秒
systemd-tmpfiles --clean /usr/lib/tmpfiles.d/* #再次尝试清除该临时文件
如图:
1.切换目录,编辑配置文件:

2.配置文件内容如图:

3.监控该目录:

4.另打开一个shell,开始测试:

5.创建一个文件:

6.尝试清除:(因为过了10s,所以清除掉了)

7.再次新建文件file1,尝试清除:(这次手速比较快,效果很明显,在文件的生命周期内没有清除掉。)

|