LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2012, 06:39 AM   #1
vp0619520
Member
 
Registered: Jan 2012
Posts: 55

Rep: Reputation: Disabled
Can I use Regular Expression with command find


Hi team,

I try this command below
Code:
find ./ -name "log\$"
,but I got nothing from it.I know I can use other command like
Code:
find ./ -name "*.log"
.Since I want to know if I can not use Regular Expression in the command "find" as using it in "grep".Thanks a lot.
 
Old 04-27-2012, 06:42 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Using the -regex you can:
Code:
find . -regex ".*.pdf$"
Hope this helps.
 
1 members found this post helpful.
Old 04-27-2012, 07:24 AM   #3
vp0619520
Member
 
Registered: Jan 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Hi,

Using the -regex you can:
Code:
find . -regex ".*.pdf$"
Hope this helps.
Thanks very much!It is work!
 
Old 04-27-2012, 07:25 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome
 
Old 04-27-2012, 01:07 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Do be careful though. The standard -name/-iname options use globbing patterns, but only apply matches to the basename of the file. But the -regex options apply to the entire path. To quote the man page:

Code:
-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'.  The regular expressions understood
	by find are by default Emacs Regular Expressions, but this can
	be changed with the -regextype option.
Check out the TESTS section of the find man page for more options.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Is there a command that can match a string with regular expression in linux ? 915086731 Linux - General 13 08-22-2011 03:45 AM
Searching for regular expression in command line Jean Of mArc Programming 9 08-11-2008 09:01 PM
PERL:how to find a blank line in a file--regular expression littletransformer Programming 4 03-27-2008 07:55 PM
regular expression [tT]h* sycamorex Programming 3 01-15-2008 05:43 PM
Need help with Regular Expression subaruwrx Linux - Newbie 6 09-04-2004 08:48 PM


All times are GMT -5. The time now is 08:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration