【问题标题】:find main directory name which doesn't contains file in sub directory在子目录中查找不包含文件的主目录名称
【发布时间】:2019-03-13 09:59:30
【问题描述】:

我有三个文件夹test1, test2,test3。在这三个文件夹下,我有两个共同的文件夹 dir1,dir2 。上述三个父文件夹中的每一个都将这两个作为子文件夹。我将在任一父目录的dir1 中拥有一个文本文件(file.txt)。

如果file.txt 在dir1 子文件夹中不存在,是否有 find 或 grep 单行命令来获取父目录名称作为输出?

例子:

ls test1 o/p: dir1, dir2

ls test2 o/p: dir1/file.txt,dir2

ls test3 o/p: dir1/file.txt,dir2

我需要一个将test1 作为输出的命令

【问题讨论】:

  • 您确定ls test2 提供此输出dir1/file.txt,dir2 吗? ls 不显示子文件夹中的文件
  • 我刚刚提到它是为了理解目录结构。

标签: linux shell command


【解决方案1】:

下面的内容应该可以满足您的需要:

for f in test*/dir1/ 
do 
  [[ $(find "$f" -name "file.txt") ]] || echo `dirname "$f"`  
done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多