How to use locate and exclude certain strings?

Brian Cluff brian at snaptek.com
Tue Dec 23 14:38:57 MST 2014


Perhaps you can do what you want by limiting your locate search more and 
possibly putting more than one search on the line.
Your locate line would be written better as:

locate /home/joe/mydata/*$file*

you can put more than one search pattern on the same command so if you 
really just want to look in a couple of directories you could do:

locate /home/joe/mydata/dir1/*$file* /home/joe/mydata/dir2/*$file*
same thing only cleaner:
locate /home/joe/mydata/{dir1,dir2}/*$file*

if you really want to do an, "everything except a certain thing" 
command, you can do:

locate /home/joe/mydata/*$file* |grep -v 'not_this'

Brian Cluff

On 12/23/2014 02:20 PM, joe at actionline.com wrote:
> I use the following command to locate all files that contain a specified
> string (i.e. $FILE) within a specified directory:
>
> locate $FILE | fgrep -ya "/home/joe/mydata"
>
> How can I modify that command to do the same thing, except exclude all
> paths that contain another specified string?
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.phxlinux.org/mailman/listinfo/plug-discuss
>



More information about the PLUG-discuss mailing list