1

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.

  • you can use grep three times to find out the exact file.. – heemayl Feb 17 '15 at 16:18
3

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. Unfortunately it doesn't support multiple conjunctive search terms, so you need grep too:

locate -ib income | grep -i personal | grep -i tax

Since you're going to look at the search result anyway, it may be better to search for a superset (in case your memory doesn't serve you well):

locate -ib income
  • David, OP wants to search based on the contents of the files, not filenames. "tax", "personal", "states" are actually contents of the files, the names are to be found. – heemayl Feb 18 '15 at 0:50
  • @heemayl: Read the question again: “I'm looking for a search tool […] that will allow me to search in filenames” and “I have a file whose name contains the words ‘personal’, ‘income’, ‘tax’, ‘state’” (emphasis by me) – David Foerster Feb 18 '15 at 0:52
  • Ooops..my bad....then my answer is not correct..i don't know how it helped OP to be honest..actually he made his own based on mine..your answer (or Ruedinger's) should be selected as the correct one. – heemayl Feb 18 '15 at 1:00
  • @heemayl OP did ls | grep. :( (It's in the comment.) – muru Feb 18 '15 at 1:00
  • @muru: I have left a comment, hope OP checks again. I don't know what to do, should i delete my answer or modify it? – heemayl Feb 18 '15 at 1:03
1

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.

  • Thanks for clueing me into this use of grep. Since I only wanted to search within filenames (not file contents) I modified your suggestion slightly and it works great. Here's what I did: <br/> 1. went to top directory using cd; <br/> 2. Typed this: <br/> ls -R | grep -i "income" | grep -i "tax" | grep -i "state" | grep -i "personal" <br/> That worked quickly and gave me the results I was looking for. – gj7755 Feb 18 '15 at 0:38
  • @gj7755: Glad it helped. The directory in my answer is just a prototype, you need to use the correct one for your need and you did so. Also pick any of the answer that you think appropriate as the answer to your question so that others can be notified that the issue has been resolved. – heemayl Feb 18 '15 at 0:43
  • @gj7755: Please note than my answer was based on a wrong plot and hence therefore is not correct. Please check the other two answers, those are the best suited for this scenario. – heemayl Feb 18 '15 at 1:02
  • @gj7755: Since you found the final answer yourself, it would be best to write your own answer or accept one that's very similar (possibly with an edit suggestion to highlight the difference). – David Foerster Feb 18 '15 at 1:06
  • @gj7755: I have corrected my answer. – heemayl Feb 18 '15 at 1:16
0

What I typically do is in my home directory find . | grep 'SEARCHTERM1\|SEARCHTERM2'

  • Or: find . -regex 'SEARCHTERM1\|SEARCHTERM2'. – muru Feb 18 '15 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.