如何使用find测试目录是否为空 [英] How to test if a directory is empty with find

查看:46
本文介绍了如何使用find测试目录是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 unix shell 脚本中编写一个 if 语句,如果它为空则返回 true,否则返回 false.

这种东西...

如果目录 foo 为空,则回声空别的回声不为空菲

我该怎么做?有人告诉我 find 是一个不错的起点

解决方案

简单 - 使用 -empty 标志.引用查找手册页:

<块引用>

 -empty 如果当前文件或目录为空,则为真.

比如:

查找.-type d -空

将列出所有空目录.

I am trying to write an if statement in a unix shell script that returns true if it's empty, and false if it's not.

This type of thing...

if directory foo is empty then
echo empty
else
echo not empty
fi

How do I do this? I'm told find is a good palce to start

解决方案

Simple - use the -empty flag. Quoting the find man page:

 -empty  True if the current file or directory is empty.

So something like:

find . -type d -empty

Will list all the empty directories.

这篇关于如何使用find测试目录是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆