LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 05: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, 05:42 AM   #2
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Using the -regex you can:
Code:
find . -regex ".*.pdf$"
Hope this helps.
 
1 members found this post helpful.
Old 04-27-2012, 06: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, 06:25 AM   #4
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
Old 04-27-2012, 12:07 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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 02:45 AM
Searching for regular expression in command line Jean Of mArc Programming 9 08-11-2008 08:01 PM
PERL:how to find a blank line in a file--regular expression littletransformer Programming 4 03-27-2008 06:55 PM
regular expression [tT]h* sycamorex Programming 3 01-15-2008 04:43 PM
Need help with Regular Expression subaruwrx Linux - Newbie 6 09-04-2004 07:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:33 PM.

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
Open Source Consulting | Domain Registration