首页 > 系统相关 >linux 中 如何判断文件夹是否为空

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

时间:2022-12-08 23:22:09浏览次数:34  
标签:test1 test2 PC1 文件夹 为空 linux test root

 

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

 

标签:test1,test2,PC1,文件夹,为空,linux,test,root
From: https://www.cnblogs.com/liujiaxin2018/p/16967719.html

相关文章

  • linux 中判断变量是否已经赋值
     001、[root@PC1test]#a=10[root@PC1test]#echo$a10[root@PC1test]#echo$b[root@PC1test]#[-z$a]##如果变量没有被赋值,则返回真,否则返回......
  • 期末复习-操作系统与linux管理
    liunx操作系统第一章操作系统引论p2-p51.什么是操作系统操作系统是管理和控制着计算机系统中的各种软硬件资源,合理地组织计算机的工作流程,为用户使用计算机提供接口......
  • linux 中判断文件是否为空
     001、[root@PC1test]#ls[root@PC1test]#toucha.txt##测试文件[root@PC1test]#seq6>b.txt##测试文件[root@PC1test]#ca......
  • Linux日志审计
    本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/291常用命令find、grep、egrep、awk、sedLinux中常见日志以及位置/v......
  • linux编译安装时常见错误解决办法
     linux编译安装时常见错误解决办法configure:error:xslt-confignotfound.Pleasereinstallthelibxslt>=1.1.0distribution复制代码代码如下:yum-yinstallli......
  • 递归复制文件夹
    packagecom.simon.myfinal;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;/**......
  • Linux如何查看服务启动状态是否开机自动启动
    本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/284方式一chkconfiglinux中查看服务启动状态是否开机自动启动的方法:1......
  • Linux系统的开机自启动
    本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/285当你使用windows操作系统时,开机后总会有各种软件自我启动完成,你并没有......
  • linux安装php5
    yum-yinstallbzip2bzip2-devellibxml2libxml2-developensslopenssl-develcurl-devellibjpeg-devellibpng-develfreeType-devellibmcrypt-develmhashgdg......
  • 工具推荐:Netdata,Linux性能实时监测工具
    工具推荐:Netdata,Linux性能实时监测工具​​​http://www.freebuf.com/sectool/100484.htm​​​安装使用教程:https://linux.cn/article-7576-1.html......