Linux命令:目录中的目录

发布于 2024-07-17 12:50:49 字数 184 浏览 3 评论 0原文

所以我有一个目录 - 比如说/dir/。 其中我有这些文件夹- /目录/折叠1/ /目录/fold2/ /dir/fold3/

这些文件夹中的每一个 (fold1,2,3) 都可能包含一个名为 foo 的文件夹。 我想列出 dir 内的所有文件夹,其中有一个名为 foo 的文件夹。

谢谢!

So I have have a directory - lets say /dir/.
In it I have these folders-
/dir/fold1/
/dir/fold2/
/dir/fold3/

each of these folders (fold1,2,3) may contain a folder called foo. I want to list all the folders inside dir, that have inside them a folder called foo.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

执妄 2024-07-24 12:50:49

怎么样

ls -R /dir | grep -i foo

分解一下我们的命令 :
ls -R = 递归列出文件(包括目录

grep -i foo = 将采用上面的命令并对其进行不区分大小写的过滤,以显示“foo”的任何实例。

What about

ls -R /dir | grep -i foo

Breaking down the command we have:
ls -R = Lists files recursively (including directories

grep -i foo = Will take the command above and filter it case-insensitive to display any instances of 'foo'.

意中人 2024-07-24 12:50:49

使用这个:

find dir -type d -name foo

所以... dir 是您要搜索的目录。

-type 是您要查找的内容的类型:d目录、文件文件或l墨水。

-name 是您要查找的内容的名称,区分大小写。 如果您希望不区分大小写,可以使用 -iname

use this:

find dir -type d -name foo

So... dir is the directory you want to search.

-type is they type of what you're looking for: directory, file or link.

-name is the name of what you're looking for, case sensitive. You can use -iname if you want it to be case insensitive.

望喜 2024-07-24 12:50:49
ls -ld /dir/*/foo | grep ^d
ls -ld /dir/*/foo | grep ^d
嘴硬脾气大 2024-07-24 12:50:49

我建议:

find /dir -name foo -type d -exec dirname {} \; | xargs ls

但是如果任何目录中有空格,这将不起作用。

I propose:

find /dir -name foo -type d -exec dirname {} \; | xargs ls

but this does not work if any directory has whitespaces in it.

宁愿没拥抱 2024-07-24 12:50:49

如果您想列出第一级仅包含名为 foo 的子目录的所有目录,您可以执行

for x in /dir/*; do
  [ -d $x/foo ] && ls $x
done

[ ... ] 结构是shell 内置测试-d $x/foo 测试 $x/foo 是否存在并且是一个目录。 如果是,则执行ls $x

If you want to list all of the directories which only contain a subdirectory named foo at the first level, you can do

for x in /dir/*; do
  [ -d $x/foo ] && ls $x
done

The [ ... ] construct is an abbreviation for the shell built-in test. -d $x/foo tests if the $x/foo exists and is a directory. If it does, then ls $x is executed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文