find清空文件

find清空文件

find清空文件【经典】
-----方式1------------
[root@vps18 test]# cat a
aaaa
[root@vps18 test]# cat b
bbbb
[root@vps18 test]# find ./ -mtime -1 -type f -print | awk '{print ">",$0}' | bash
[root@vps18 test]# cat a b
[root@vps18 test]#
此处构造出来 "> file"  字符串,然后传递给bash来执行,非常精妙
如果报bash路径问题,补全bash为 /bin/bash即可
----------方式2-----------
find ./ -mtime -1 -type f -exec cp /dev/null {} \;
此种方式亦可,是通过拷贝覆盖来实现清空;不过从效率来看,方式1的>内置命令应该更快些