查找空目录Linux,查找空文件夹

find . -name “*” -type f -size 0c | xargs -n 1 rm -f

就是删除1k大小的文件。(但注意不要用 -size 1k,这个得到的是占用空间1k,不是文件大小1k的)。用这个还可以删除指定大小的文件,只要修改对应的 -size 参数就行,例如:

find . -name “*” -type f -size 1024c | xargs -n 1 rm -f

find查找空文件夹

read -p ‘please input dir name: ‘ path

find ${var_path:=/tmp} -type d -empty

查询所有/root/下的空文件夹

find /root -type d -empty

# cat empty_dir.sh

#!/bin/bash

##############################################################

# File Name: empty_dir.sh

# Version: V1.0

# Author: frs

# Organization: https://www.todocker.cn

# Created Time : 2019-09-18 11:48:17

# Description:

##############################################################

var_path=$1

read -p ‘please input yes|y|Y:’ a

if [ $a == ‘yes’ -o $a == ‘y’ -o $a == ‘Y’ ]

then

for n in `ls -A ${var_path:=$PWD}`

do

file_num=`ls -A $n|wc -w`

if [ $file_num -eq 0 ]

then

rm -rf $n

fi

done

else

exit 1

fi

赞赏

    原文作者:LKEG
    原文地址: https://blog.csdn.net/weixin_33345090/article/details/116553576
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞