delete_file.sh

#!/bin/bash

#删除某个目录下大小为 0 的文件
dir="/tmp"
find $dir -type f -size 0 -exec rm -rf {} \;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

验证:

[root@logstash tmp]# ls *.txt
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt
[root@logstash tmp]# sh /root/delete_file.sh 
[root@logstash tmp]# ls *.txt
ls: cannot access *.txt: No such file or directory
[root@logstash tmp]#
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.