简体   繁体   English

linux find命令无法正常工作

[英]linux find command is not working properly

I am using Linux(Ubuntu), I am trying to find the files, but it is not working properly. 我正在使用Linux(Ubuntu),我正在尝试查找文件,但它无法正常工作。 I have created some files in my directory structure, for example: World/India/Maharashtra/Pune/filename.xml 我在我的目录结构中创建了一些文件,例如: 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. 如果有人知道如何解决这个问题,请尽快回复我。

双引号搜索字符串和-L使其符合符号链接:

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

Yes, as mentioned you have to double qoute your -name argument or use a backslash prior to the * . 是的,如上所述,你必须加倍qoute你的-name参数或在*之前使用反斜杠。 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. 它不能从一个目录工作,但在其他目录中正常工作的原因是*字符用于shell生成文件名。 This of course happens before the find command is executed. 这当然发生在执行find命令之前。 Therefore, if you have a file that match the filename*.xml pattern in your current directory it will be substituted before find is executed, which is not what you want. 因此,如果您有一个与当前目录中的filename*.xml模式匹配的filename*.xml ,它将在执行find之前被替换,这不是您想要的。 On the other hand, if there is no pattern match in the current directory, the * character is passed on to the find command unmodified. 另一方面,如果当前目录中没有模式匹配,则将*字符传递给未修改的find命令。 By qouting you protect the string from shell filename generation. 通过qouting你保护字符串免受shell文件名生成。

Regards 问候

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 . 我不能让它继续遍历子目录,除非我用a逃脱了*。

Give this a try: 尝试一下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM