如何在 linux 命令行上找到可能位于任何位置的文件/目录? [英] How can I find a file/directory that could be anywhere on linux command line?

查看:8
本文介绍了如何在 linux 命令行上找到可能位于任何位置的文件/目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我可以使用像

Ideally, I would be able to use a program like

find [file or directory name]

报告具有匹配文件名/目录的路径.不幸的是,这似乎只检查当前目录,而不是整个文件夹.

to report the paths with matching filenames/directories. Unfortunately this seems to only check the current directory, not the entire folder.

我也试过 locate 和 which,但没有找到该文件,即使我知道它在某处的计算机上.

I've also tried locate and which, but none find the file, even though I know its on the computer somewhere.

推荐答案

不幸的是,这似乎只检查当前目录,而不是整个文件夹".大概您的意思是它不在子目录中.要解决此问题,请使用 find -name "filename"

"Unfortunately this seems to only check the current directory, not the entire folder". Presumably you mean it doesn't look in subdirectories. To fix this, use find -name "filename"

如果有问题的文件不在当前工作目录中,你可以通过

If the file in question is not in the current working directory, you can search your entire machine via

find / -name "filename"

这也适用于 find/-name "*.pdf" 等内容.有时我也喜欢将其通过管道传递到 grep 语句中(因为至少在我的机器上,它突出显示结果),所以我最终得到类似

This also works with stuff like find / -name "*.pdf", etc. Sometimes I like to pipe that into a grep statement as well (since, on my machine at least, it highlights the results), so I end up with something like

find / -name "*star*wars*" | grep star

这样做或类似的方法只是帮助我立即找到文件名并识别它是否确实是我正在寻找的文件.

Doing this or a similar method just helps me instantly find the filename and recognize if it is in fact the file I am looking for.

这篇关于如何在 linux 命令行上找到可能位于任何位置的文件/目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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