Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
find option like grep?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
_______0
Guru
Guru


Joined: 15 Oct 2012
Posts: 521

PostPosted: Sat Nov 02, 2013 7:05 pm    Post subject: find option like grep? Reply with quote

hi,

The command find is useful but its options' semantics make it slow.

dis crazy:

'libavcodec*' or '*foo*'

Does find have an option for fuzzy search like grep? And banish quotes entirely.

The ideal option, for certain stuff is this:

find ./ -iname 'portion of file name' (without the quotes)

the following example:

Code:
find ./ -iname codec


would return this

Code:
libavcodec.so.53
libavcodec.so.54
libavcodec.so


thanks.
Back to top
View user's profile Send private message
Atom2
Tux's lil' helper
Tux's lil' helper


Joined: 01 Aug 2011
Posts: 86

PostPosted: Sat Nov 02, 2013 8:23 pm    Post subject: Reply with quote

I am not aware that find (alone) can do what you are after. Having said that, I think there are two options to achieve what you want:

In case you wanna get rid of the the quoting mechanism and use parts of a file name as the matching criteria, you could use output redirection into a file and then grep that file or, in case you want everything in one command, pipe find's output directly to grep (which I'd prefer). That should not be too slow if you instruct find to only print out the names of files (it would just traverse every directory and print the file names which is actually pretty fast) and let grep do the search for the 'portion of file name' as you have put it. If there's no terminal output involved, this is very fast indeed.

If, on the other hand, you are after more flexibility in the search pattern (like grep's regular expressions) then you could combine
Code:
find -regextype
to set the types of regular expressions that find understands and combine this option with
Code:
find -regex
for case sensitive searches or
Code:
find -iregex
for case insensitive searches.

It's probably worth noting that quoting the search strings is required with grep and find (and also any other command) to protect wildcard characters from being interpreted by the shell before being passed to the command as an argument. So the quoting is not really special to find at all.

I hope that helps.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum