linux find 命令无法正常工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4537909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:18:31  来源:igfitidea点击:

linux find command is not working properly

linux

提问by Lokesh Paunikar

I am using Linux(Ubuntu), I am trying to find the files, but it is not working properly. I have created some files in my directory structure, for example: World/India/Maharashtra/Pune/filename.xml

我正在使用 Linux(Ubuntu),我正在尝试查找文件,但它无法正常工作。我在目录结构中创建了一些文件,例如:World/India/Maharashtra/Pune/filename.xml

When I use the find command like:

当我使用 find 命令时:

find /home/lokesh/Desktop/Testing_India2/Test/World/India/Maharashtra/ -name filename*.xml -mmin -3000

It is giving the result perfectly.

它完美地给出了结果。

But, when I am using the same command at "World" or "India" level:

但是,当我在“世界”或“印度”级别使用相同的命令时:

find /home/lokesh/Desktop/Testing_India2/Test/World/ -name filename*.xml -mmin -3000

it does not give any result.

它没有给出任何结果。

I have lots of directories at "India" level as well as at "Maharashtra" level and may be some directories within "Maharashtra's" inner directories. I have to find each file created in all directories. And I have mounted all folders from different machine.(I mean some state from different and some from different machine.)

我有很多“印度”级别和“马哈拉施特拉”级别的目录,可能是“马哈拉施特拉”内部目录中的一些目录。我必须找到在所有目录中创建的每个文件。我已经安装了来自不同机器的所有文件夹。(我的意思是来自不同机器的一些状态和来自不同机器的一些状态。)

If someone knows how to solve this problem please reply me as soon as possible.

如果有人知道如何解决这个问题,请尽快回复我。

采纳答案by ismail

Double quote your search string and -Lto make it follow symbolic links:

双引号您的搜索字符串并-L使其遵循符号链接:

find -L /home/lokesh/Desktop/Testing_India2/Test/World/ -name "filename*.xml" -mmin -30000

回答by TDarwin

This is something I ran into earlier today actually when using the '*' wildcard. I couldn't get it to continually traverse the subdirectories unless I escaped the * with a .

这是我今天早些时候在使用“*”通配符时遇到的问题。我无法让它连续遍历子目录,除非我用 .

Give this a try:

试试这个:

find -L /home/lokesh/Desktop/Testing_India2/Test/World/ -name filename\*.xml -mmin -30000

回答by KlausCPH

Yes, as mentioned you have to double qoute your -nameargument or use a backslash prior to the *. The reason for it not working from one directory, but working fine in other directories, is that the *character is used for filename generation by your shell. This of course happens before the findcommand is executed. Therefore, if you have a file that match the filename*.xmlpattern in your current directory it will be substituted before findis executed, which is not what you want. On the other hand, if there is no pattern match in the current directory, the *character is passed on to the find command unmodified. By qouting you protect the string from shell filename generation.

是的,如前所述,您必须对您的-name论点进行双重引用或在*. 它不能在一个目录中工作,但在其他目录中工作正常的原因是该*字符用于您的 shell 生成文件名。这当然发生在find命令执行之前。因此,如果您有一个与filename*.xml当前目录中的模式匹配的文件,它将在find执行之前被替换,这不是您想要的。另一方面,如果当前目录中没有模式匹配,则该*字符将不加修改地传递给 find 命令。通过 qouting,您可以保护字符串免受 shell 文件名生成的影响。

Regards

问候