公告
财富商城
积分规则
提问
发文
2019-07-19 09:00发布
孤傲高冷的网名
In shell script,
how to check whether a directory is non-empty on a remote machine?
Regards
find PATH_TO_REMOTE_DIRECTORY -maxdepth 0 -not -empty
-maxdepth 0 will make sure you only check the directory, and not all subdirectories recursively.
-maxdepth 0
-not -empty is straightforward.
-not -empty
This will print the path if not empty, and will print nothing if empty.
And, of course, run it via ssh.
ssh
One possibility is to execute the command mentioned in this answer via ssh:
if [ "$(ssh user@host ls -A /dir/ 2>/dev/null)" == "" ]; then echo "empty"; else echo "not empty"; fi
Note: non-existing directories will also be reported as empty.
最多设置5个标签!
find PATH_TO_REMOTE_DIRECTORY -maxdepth 0 -not -empty
-maxdepth 0
will make sure you only check the directory, and not all subdirectories recursively.-not -empty
is straightforward.This will print the path if not empty, and will print nothing if empty.
And, of course, run it via
ssh
.One possibility is to execute the command mentioned in this answer via
ssh
:if [ "$(ssh user@host ls -A /dir/ 2>/dev/null)" == "" ]; then echo "empty"; else echo "not empty"; fi
Note: non-existing directories will also be reported as empty.