[英]How to traverse dirs in linux and cd into a specific dir
I have a file structure as following:我有一个文件结构如下:
/home/myhome/me/staging/15/1234/my_stats/
/home/myhome/me/staging/16/5678/my_stats/
/home/myhome/me/staging/17/7890/my_stats/
/home/myhome/me/staging/18/3456/my_stats/
I need to travel to the dir "my_stats" and execute query to find files in my cmd. There are multiple dirs in "staging" and I need to go into every one of them and check if 'my_stats' dir exists.我需要前往目录“my_stats”并执行查询以在我的 cmd 中查找文件。“暂存”中有多个目录,我需要将 go 放入其中的每个目录并检查“my_stats”目录是否存在。 If it exists, then I need to run a cmd query in "my_stats" dir.
如果它存在,那么我需要在“my_stats”目录中运行 cmd 查询。
The dir structure will always be in the following format:目录结构将始终采用以下格式:
/home/myhome/me/staging/<2 digit name>/<4 digit name>/my_stats/
I have tried iterating through the structure using a nested for loop and checking all dirs in 'staging' which is proving to be slow.我已经尝试使用嵌套的 for 循环遍历结构并检查“暂存”中的所有目录,这被证明很慢。 Is there a way to using the 'find' command with 'depth' to do the same?
有没有办法使用带有“深度”的“查找”命令来做同样的事情? Or can we implement this with pattern matching?
或者我们可以用模式匹配来实现吗?
Appreciate the help.感谢帮助。 Thanks!
谢谢!
found the answer.找到了答案。 we can use * for it.
我们可以使用 * 作为它。
/home/myhome/me/staging/*/**/my_stats/*
Will try to find a better solution which can maybe use len of dir to better differentiate it将尝试找到一个更好的解决方案,可以使用 len of dir 来更好地区分它
Try this one试试这个
find . -type f -path "./[0-9][0-9]/[0-9][0-9][0-9][0-9]/my_stats/*"
can replace the .
可以代替
.
with your own path.用你自己的道路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.