ee23
![]() |
|
|
|
|
|||||||
| General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
Hi,
This question is purely academic. A simple Code:
ls /bin | egrep '^..$' But for some reason this doesn't work Code:
find -E /bin -regex '^..$'
__________________
The American lifestyle is not negotiable. Last edited by DutchDaemon; September 20th, 2011 at 01:00. |
|
#2
|
||||
|
||||
|
Not entirely sure as I never use find regex's, though ls will output only the filename while find will produce the full path.
|
|
#3
|
|||
|
|||
|
You're matching the whole string with -regex so you have to account for the /bin/ at the beginning.
Code:
find -E /bin -regex '.*/..$' |
| The Following User Says Thank You to kpa For This Useful Post: | ||
Business_Woman (September 19th, 2011) | ||
|
#4
|
||||
|
||||
|
Thank you.
__________________
The American lifestyle is not negotiable. |
|
#5
|
||||
|
||||
|
find(1):
Code:
-regex pattern
True if the whole path of the file matches pattern using regular
expression. To match a file named “./foo/xyzzy”, you can use the
regular expression “.*/[xyz]*” or “.*/foo/.*”, but not “xyzzy” or
“/foo/”.
Code:
% find -E /bin -print /bin /bin/cat /bin/chflags /bin/chmod /bin/cp /bin/chio ... |
|
#6
|
||||
|
||||
|
yes, sorry. I should have read the man page more careful >_>
If i want to match all binaries in /bin that are three characters long and starts with 'p'. Code:
find -E /bin -regex '\( .*/.. -and -regex '.*\^p \)'
__________________
The American lifestyle is not negotiable. |
|
#7
|
||||
|
||||
|
Easier to do in a single regex:
% find /bin -regex '.*/p..$'But for this use, ls and grep are more appropriate, shorter and simpler. % ls /bin | grep '^p..$'
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] simple regex (not for me) | vingtage | Userland Programming & Scripting | 3 | May 20th, 2010 21:38 |
| [Solved] RegEx Not Matching - Why??? | Ruler2112 | Web & Network Services | 6 | March 15th, 2010 23:42 |
| variable in grep regex | Just_Johnny | Userland Programming & Scripting | 1 | November 1st, 2009 09:47 |
| C++ regex: is there a way to use (.*?) | ChrisCphDK | Userland Programming & Scripting | 7 | August 15th, 2009 10:36 |
| [Solved] find and regex | clinty | Userland Programming & Scripting | 4 | February 27th, 2009 18:32 |