cof*_*fee 1 unix linux scripting
我正在尝试在 unix shell 脚本中编写一个 if 语句,如果它为空则返回 true,否则返回 false。
这种东西...
if directory foo is empty then
echo empty
else
echo not empty
fi
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?有人告诉我 find 是一个很好的起点
简单 - 使用 -empty 标志。引用查找手册页:
Run Code Online (Sandbox Code Playgroud)-empty True if the current file or directory is empty.
所以像:
find . -type d -empty
Run Code Online (Sandbox Code Playgroud)
将列出所有空目录。