Linux命令找到一个目录并去那里
发布时间:2020-05-23 20:57:33 所属栏目:Linux 来源:互联网
导读:我想找到保存某个文件和CD的目录.例如 find * -name hello.txt 输出:Documents / Projects / hello.txt cd Documents/Projects 如何管理这些命令?谢谢! 尝试 cd $(dirname$(find /path -name hello.txt | head -n 1)) 要么 cd $(find /path -name hel
|
我想找到保存某个文件和CD的目录.例如 find * -name hello.txt 输出:Documents / Projects / hello.txt cd Documents/Projects 如何管理这些命令?谢谢! 解决方法尝试cd $(dirname$(find /path -name hello.txt | head -n 1)) 要么 cd $(find /path -name hello.txt | head -n 1 | xargs dirname) 你需要提供一个搜索路径,*在你的上面不会工作,因为shell会扩展它. 编辑,如果你的文件名中有空格 cd $(find /home -name 'he llo.txt' -print0 -quit | xargs -0 dirname) 如果你的目录名也有空格 cd "$(find /path -name 'hello.txt' -print0 -quit | xargs -0 dirname)" (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
