简体   繁体   中英

Linux Find Command

What am I doing wrong with the FIND command? 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, …

To match the directories A1 , AF , AV , use the pattern A[1FV] or {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. 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.

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. What you really need is this, since each block [] of letters matches a single character: /A[1FV]/

Since each of your samples begins with the letter A, you don't need it in a [].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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