How can you search only filenames by find? [closed]

痞子三分冷 提交于 2019-12-13 07:41:09

问题


This question is based on the answer.

I run at home

find -- ./ Desktop                                       

I understand the command as

  1. find without parameters at the current directory that is home (= /Users/masi/)
  2. find the folder name Desktop at the current directory

How do you read the command?


回答1:


I think what you want is:

find ./ -name Desktop



回答2:


The answer to your question in the title is

$ find . -type f

Now, keep in mind that

$ find -- ./ Desktop

will return the files in Desktop twice.




回答3:


In your example, "--" says to stop looking for further options. Everything else after that is a path, so it finds anything else matching that. And since "./" means "the current directory" it matches everything under the current directory (the Desktop will cause that directory, as well as anything inside it, to be reported twice.)

You probably want something like:

find ./Desktop -type f

Which will find any files inside the ./Desktop directory, that is a file (not directories, symbolic links, etc...)

I know that manpages can be quite technical sometimes, but "man find" will give you a wealth of other options that might help, as well as a few examples that may help with common problems.




回答4:


Well, you can pass multiple directories to search to find:

$ find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[...]

Note the "[path...]" indicating you can specify multiple paths.

So your example will find all files and directories under ./ (current dir) and under Desktop.



来源:https://stackoverflow.com/questions/1122116/how-can-you-search-only-filenames-by-find

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!