Tuesday, June 22, 2010

How to use regex in find command

Today I discovered how to use regex in unixs' find command. It has a very simple syntax as below:

Syntax: find \path\ -regex '\regex pattern\'
e.g. find ./ -regex 'file[0-9]+.txt'

In above example, we are looking for files with name like file1.txt or file23.txt or file567.txt. 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'.

According to find man page, it is also possible to specify the type of regex to be used, like emacs regex, posix-awk, posix-basic, posix-egrep and posix-extended. Default is emacs regex.

Another option is -iregex. It is just like -regex, but the match is case insensitive.

1 comment:

  1. King Casino Login | All your games online and - Community Khabar
    Login King Casino, Play, and Win! Login King Casino, Play. sol.edu.kg Login King Casino, Play. kadangpintar Login King ventureberg.com/ Casino, Play. Login King Casino, Play. Login King Casino, Play. Login King communitykhabar Casino,

    ReplyDelete