按名称查找了目录树中的文件,使用bash [英] Find file by name up the directory tree, using bash

查看:186
本文介绍了按名称查找了目录树中的文件,使用bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用庆典,我怎么能找到与特定名称的文件的地方了从目录树中的PWD

Using bash, how can I find a file with a specific name somewhere up the directory tree from the pwd?

要更加清晰。我想找到我的工作目录的根坐在一个文件,但我不知道在哪里的根,我的 PWD 可能是根目录下的任何地方。

To be more clear. I want to find a file that sits in my working directory's root, but I don't know where the root is, and my pwd might be anywhere below the root.

推荐答案

查找 file.txt的达根

$ x=`pwd`; while [ "$x" != "/" ] ; do x=`dirname "$x"`; find "$x" -maxdepth 1 -name file.txt; done

这篇关于按名称查找了目录树中的文件,使用bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆