Linux命令:目录中的目录
所以我有一个目录 - 比如说/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
怎么样
分解一下我们的命令 :
ls -R
= 递归列出文件(包括目录grep -i foo
= 将采用上面的命令并对其进行不区分大小写的过滤,以显示“foo”的任何实例。What about
Breaking down the command we have:
ls -R
= Lists files recursively (including directoriesgrep -i foo
= Will take the command above and filter it case-insensitive to display any instances of 'foo'.使用这个:
所以...
dir
是您要搜索的目录。-type
是您要查找的内容的类型:d目录、文件文件或l墨水。-name
是您要查找的内容的名称,区分大小写。 如果您希望不区分大小写,可以使用-iname
。use this:
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.我建议:
但是如果任何目录中有空格,这将不起作用。
I propose:
but this does not work if any directory has whitespaces in it.
如果您想列出第一级仅包含名为
foo
的子目录的所有目录,您可以执行[ ... ]
结构是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 doThe
[ ... ]
construct is an abbreviation for the shell built-intest
.-d $x/foo
tests if the$x/foo
exists and is a directory. If it does, thenls $x
is executed.