我怎样才能找到一个文件/目录,可以在任何地方在Linux命令行? [英] How can I find a file/directory that could be anywhere on linux command line?
问题描述
$ b $ pre $ find $文件或目录名
报告具有匹配文件名/目录的路径。不幸的是,这似乎只检查当前目录,而不是整个文件夹。
我也试过找到和哪个,但没有找到该文件,即使我知道它在电脑的某个地方。
不幸的是,这似乎只检查当前目录,而不是整个文件夹。大概你的意思是它不看在子目录。要解决这个问题,使用 find -namefilename
如果有问题的文件不在当前工作目录下,你可以通过
find / -namefilename
这也适用于 find / -name* .pdf
等等。有时候我也喜欢把它变成一个grep语句(因为至少在我的机器上,它会突出显示结果),所以我最终得到了类似于
find / -name* star * wars *| grep star
执行此操作或类似的方法只是帮助我立即找到文件名并识别它是否在实际上我正在寻找的文件。
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.
I've also tried locate and which, but none find the file, even though I know its on the computer somewhere.
"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"
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屋!