bash UNIX:如果给定部分路径,如何使用 find 命令查找完整路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36849003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UNIX: How to use find command to find full path if given partial path
提问by James the Great
I know how to find files using
我知道如何使用
find . -name "file_name"
But if I am given one part of a path, say "folder1/subfolder2/", how do I get all the full path that contains this partial path?
但是,如果给我路径的一部分,例如“文件夹 1/子文件夹 2/”,我如何获得包含此部分路径的所有完整路径?
Example
例子
partial path: folder1/subfolder2/
部分路径: folder1/subfolder2/
desire result:
愿望结果:
/bob/folder1/subfolder2/yo/
/sandy/folder1/subfolder2/hi/
回答by hek2mgl
Use the -wholename
option instead of -name
:
使用该-wholename
选项而不是-name
:
find FOLDER -wholename '*folder1/folder2/*'
回答by Vrata Blazek
This one worked for me (using bash)
这个对我有用(使用bash)
ls -l /**/folder1/subfolder2/**
回答by sjsam
You may do it like below:
你可以像下面这样做:
find . -path "*folder1/folder2" -prune -exec find {} -type f -name file.txt \;
With -prune
you don't recurse after first match in a directory
随着-prune
你在一个目录下的第一场比赛后,不递归
回答by mcabreb
Expanding from @hek2mgl,
从@hek2mgl 扩展,
find / -wholename '*folder1/subfolder2/*'