linux 中 如何判断文件夹是否为空

 

001、

复制代码
[root@PC1 test]# ls
[root@PC1 test]# mkdir test1 test2                 ## 测试文件夹
[root@PC1 test]# echo "xxx" > test2/a.txt
[root@PC1 test]# ls
test1  test2
[root@PC1 test]# tree
.
├── test1
└── test2
    └── a.txt

2 directories, 1 file
[root@PC1 test]# [ $(ls test1 | wc -l) -eq 0 ]        ## 如果文件夹为空,返回真
[root@PC1 test]# echo $?
0
[root@PC1 test]# [ $(ls test2 | wc -l) -eq 0 ]        ## 如果文件夹不为空,返回假
[root@PC1 test]# echo $?
1
复制代码

 

posted @   小鲨鱼2018  阅读(905)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-12-08 dos_cmd命令行中清屏命令、获取家目录命令
2021-12-08 python中pip命令的使用
2021-12-08 ubuntu虚拟机和windows之间无法实现复制粘贴
点击右上角即可分享
微信分享提示