tags:

views:

15

answers:

2

hi all

under /tmp directory I have the following files

 file1
 file2

when I run the following find command with -regex , find command not match the files why?

  find /tmp  -regex '/file(\d{1,3})/'
A: 

From the man find page:

-regex pattern

File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3, you can use the regular expression .*bar. or .*b.*3, but not f.*r3.

Also, \d and {m,n} doesn't seem to be supported. The following works:

find /tmp -regex ".*file[0-9]+$"
Amarghosh
A: 

I asume it's unix. find /tmp -type f -exec grep -il "whatever_you_want_in_file" {} \; which recursively searches for entries in the /tmp but you probably want ls -a | grep file[0-9][0-9]?[0-9]? for /tmp only or find /tmp -regexp "file[0-9][0-9]?[0-9]?" Not all the shells support \d as a one digit wild card, also the / is not necessary. I know it's used as assignments in Perl.

dr jerry