Solved

basic regular expressions

Posted on 2011-03-06
4
399 Views
Last Modified: 2012-06-27
Hi

Take these commands:

To find all the files on the system that have the text `audio' anywhere in their name, type:
$ locate audio [RET]

To find all the files on the system whose file names end with the text `ogg', type:
$ locate *ogg [RET]

Why doesn't *ogg find files with 'ogg' anywhere in the middle of the name? Why does adding the wildcard before ogg mean you are looking for ogg at the end of the name. I would have expected the first command to be *audio*

thanks
0
Comment
Question by:andieje
4 Comments
 
LVL 3

Expert Comment

by:nickswanjan
ID: 35046543
If your search pattern is a plain string (no wildcards) then locate displays all file names in the slocate database that contain that string. If your search pattern contains wildcards, then locate only displays file names that match the pattern exactly.

You can search using a regular expression by specifying the -i option.

You can use the 'man locate' to show the locate command options on your system.

See the following links for more details:

http://www.linfo.org/locate.html

http://www.softpanorama.org/Tools/locate.shtml
0
 
LVL 84

Expert Comment

by:ozo
ID: 35047005
locate "*ogg"
would pass the * to the locate program rather than expanding the file glob on the command line before calling locate
0
 
LVL 6

Accepted Solution

by:
t-max earned 50 total points
ID: 35063270
That's not really a regular expression per se, but only a pattern.
As suggested above, here's a quote at "man locate" to check how it works:
     Shell globbing and quoting characters (``*'', ``?'', ``\'', ``['' and
     ``]'') may be used in pattern, although they will have to be escaped from
     the shell.  Preceding any character with a backslash (``\'') eliminates
     any special meaning which it may have.  The matching differs in that no
     characters must be matched explicitly, including slashes (``/'').

     As a special case, a pattern containing no globbing characters (``foo'')
     is matched as though it were ``*foo*''.
0
 

Author Closing Comment

by:andieje
ID: 35072064
thanks - i hadn't appreciated the difference between reg ex and patterns
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now