Reputation: 689
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.
Upvotes: 3
Views: 658
Reputation: 5932
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]
Upvotes: 0
Reputation: 189
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 [].
Upvotes: 0
Reputation: 265131
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}
.
Upvotes: 2
Reputation: 143856
Try:
find /home/michael/foxpro/mount/A[1FV]/[12][0-9][0-9][0-9] -name '*.dbf' -type f -exec ln -s {} \;
Upvotes: 0