How to Search for multiple words (in any order) in filename - GUI (or terminal)

I'm looking for a search tool (from Ubuntu 14.04 desktop) or method/command (Terminal) that will allow me to search in filenames for full or partial words, in any order, regardless of capitalization.

Do you know of one?

Here's an example of what I need to do. I know that somewhere under /home/myusername I have a file whose name contains the words "personal", "income" , "tax" , "state". But I can't remember if the filename is

  • state personal income tax return.doc or
  • personal Income Tax return - state.doc or
  • income tax return - State - personal.doc.

and I also can't remember if some of the words are capitalized. Also, I have a zillion other files with each of the words in them. So just doing a simple search on one of the words (like only "state", or only "tax") doesn't help me much, because it brings back too many files.

Ideally, I'd like to be able to just type in [income state return] or [state income return] and have it bring back the files with all three words in the file name, regardless of capitalization or the order of the words. A GUI tool would be preferable, but a Terminal method would be OK too.

I've tried Catfish and gnome-search-tool/"Search for Files" -- neither of them seem to work for multiple search terms unless the terms are typed in order of how they occur in the file name, with no other words in between the search terms.


Solution 1:

Don't use grep! find has a perfectly fine file name matching syntax. To use your example:

find [PATH...] -iname '*personal*' -iname '*income*' -iname '*tax*'

where [PATH...] are zero or more paths under which to search.

If you didn't disable your mlocate file name database, it may be faster to make use of it for a faster search. You can even tell it to look for multiple conjunctive search terms with the -A/--all option:

locate -i -A -b income personal tax

Solution 2:

You can use grep as many times for as much words you want to look for in the filenames. For example to find out the filenames containing the words "income", "tax", "personal" and "state" you can do the following:

ls -R /home/myusername/ | grep -i "income"  | grep -i "tax" | grep -i "personal" | grep -i "state"

Here the -i switch will ensure case-insensitivity.

NOTE:

find would be better suited for this kind of scenario. Check this answer and this answer for details.