简体   繁体   English

Linux查找命令

[英]Linux Find Command

What am I doing wrong with the FIND command? 我在FIND命令中做错了什么? I can't figure out why this works: 我无法弄清楚为什么这样有效:

find /home/michael/foxpro/mount/A1/[12][0-9][0-9][0-9] "*.dbf" -type f -exec ln -s {} \;
find /home/michael/foxpro/mount/AF/[12][0-9][0-9][0-9] "*.dbf" -type f -exec ln -s {} \;
find /home/michael/foxpro/mount/AV/[12][0-9][0-9][0-9] "*.dbf" -type f -exec ln -s {} \;

but this doesn't: 但这不是:

find /home/michael/foxpro/mount/[A1][AF][AV]/[12][0-9][0-9][0-9] "*.dbf" -type f -exec ln -s {} \;

My folder structure looks like this: 我的文件夹结构如下所示:

...../mount/A1/2012/file1.dbf
...../mount/A1/2011/file2.dbf
...../mount/A1/2010/file3.dbf
...../mount/AF/2012/file4.dbf
...../mount/AF/2011/file5.dbf
...../mount/AF/2010/file6.dbf
...

The first script when I hard code the second to last directory the find scan through all my year directories but in my second script it just gives me a "No such file or directory" error. 第一个脚本,当我硬编码第二个到最后一个目录时,查找扫描我所有的年份目录,但在我的第二个脚本中,它只给我一个“没有这样的文件或目录”错误。

The pattern [A1][AF][AV] matches the following files/directories: AAA, AAV, AFA, AFV, 1AA, 1AV, … 模式[A1][AF][AV]匹配以下文件/目录:AAA,AAV,AFA,AFV,1AA,1AV,...

To match the directories A1 , AF , AV , use the pattern A[1FV] or {A1,AF,AV} . 要匹配目录A1AFAV ,请使用模式A[1FV]{A1,AF,AV}

尝试:

find /home/michael/foxpro/mount/A[1FV]/[12][0-9][0-9][0-9] -name '*.dbf' -type f -exec ln -s {} \;

This isn't a problem with find, it's a problem with shell syntax. 这不是find的问题,它是shell语法的问题。 Here's the problem: 这是问题所在:

[A1][AF][AV]

This gives you combinations like AAA, 1FV, AFV, etc. The bracket syntax matches one character in each group, it is not a choice between the groups. 这为您提供了AAA,1FV,AFV等组合。括号语法匹配每个组中的一个字符,它们不是组之间的选择。

In your case, I think this should work: 在你的情况下,我认为这应该工作:

/home/michael/foxpro/mount/A[1FV]/[12][0-9][0-9][0-9]

I believe the problem is with your regex. 我相信问题在于你的正则表达式。 What you have is this: /[A1][AF][AV]/ which will match AAA, AAV, AFA, AFV, 1AA, 1AV, 1FA, and 1FV. 你有这个:/ [A1] [AF] [AV] /它将匹配AAA,AAV,AFA,AFV,1AA,1AV,1FA和1FV。 What you really need is this, since each block [] of letters matches a single character: /A[1FV]/ 你真正需要的是这个,因为每个字母块[]匹配一个字符:/ A [1FV] /

Since each of your samples begins with the letter A, you don't need it in a []. 由于每个样本都以字母A开头,因此在[]中不需要它。

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

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