1

Is there a CLI tool similar to gnome-search-tool? I'm using locate, but I'd prefer that it grouped results where directory name is matched. I get a lot of results where the path is matched which is not what I want:

/tmp/dir_match/xyz
/tmp/dir_match/xyz2/xyz3

It needs to be fast and thus use a search index.

  • One should not forget the capabilities of global search from within Emacs using helm or ivy. – m33lky Feb 21 '18 at 19:31
1

locate is very versatile can take -r and a regexp pattern, so you can do lots of sophisticated matching. For example, to match directories a a0 a1 and so on use '/a[0-9]*/'. This will only show directories with files in them since you need the second / in the path. To match the directory alone use $ to anchor the pattern to the end of the path, '/a[0-9]*$'.

Note, there are at least 2 versions of the locate command, one from GNU, and one from Redhat (known as mlocate). Use --version to find which you have. They differ slightly in the regex style. For example, if we change the above pattern '/a[0-9]*$' to use + instead of * to avoid matching a on its own, then mlocate needs \+ and gnu just +.

For example, to match a directory a and all underneath it you might use for both versions

locate -r '/a\(/\|$\)'

For mlocate you might prefex --regex which uses extended syntax

locate --regex '/a(/|$)'

To do the same for gnu locate you would need to add option --regextype egrep, for example.

3

fzf is a general-purpose command-line fuzzy finder.

and their github page is https://github.com/junegunn/fzf

  • 2
    @GAD3R the whole point of this question is to find alternative tools, so a link to the tool is entirely appropriate... Ayyanar, it would nevertheless be interesting to add a bit more information in your answer about the fsf’s features. (You can still edit your answer to improve it!) – Stephen Kitt Feb 12 '18 at 8:57
2

Standard Linux commands for this are :

  • find command to look for file names, for example:

    • look for files named xyz in /tmp

      $ find /tmp -type f -name xyz
      
    • look for directories which name contains 'xyz' in /tmp

      $ find /tmp -type d -name '*xyz*'
      
  • find and grep commands to search in file contents, for example:

    • find files in /tmp which contain xyz

      $ find /tmp -type f -exec grep -l xyz {} \;
      
  • I've updated the question. find cannot benefit from the search index part of locate as far as I know. – m33lky Feb 12 '18 at 16:41

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.