99

Is there any utility to make searches for a string inside ASCII files to avoid command line searches?

How to make a command line search, for example for the string "test" inside all files in the directory /var/x/?

  • 15
    You really mean without using command line ? Because the best tool for that remains grep... – alci Oct 9 '12 at 8:39
  • On CLI The Silver Searcher probably does a better job. – Pablo A Mar 20 at 5:40
78

You can use searchmonkey. The tool is available in the repositories, so you can simply

sudo apt-get install searchmonkey

On the other hand, command line search with grep is really intended for that...

Here is a screenshot from searchmonkey

enter image description here

  • crashed due to too much load :( – WiredIn Dec 21 '16 at 2:40
  • 1
    i have had issues with searchmonkey. It is not trustworthy in the sense that it lets slips lots of occurrences – tony gil Feb 14 '18 at 9:25
  • how do I run "searchmonkey" from the GUI? after installed using the command line, I'd rather not use the command line – Echeban Nov 22 '18 at 14:24
153

I assume that your first question is about a GUI alternative to the grep command. I can't help you with that, I always find the command line very effective.

As for the command line, try

grep "test" /var/x/*

If you want to search recursively (i.e. not only in /var/x/, but also in subdirectories thereof), do

grep -R "test" /var/x/

To avoid grepping the files which grep thinks to be binary, use the -I option:

grep -I "test" /var/x/

If grep thinks a file is binary (based on first few bytes of the file), it will assume it does not match instead of going through the whole file.

  • 1
    Will it work if the folder contain some non-ascii files? – Anwar Oct 9 '12 at 8:47
  • 1
    Well, grep will also try search for the string in a binary file, and report it if it matches: Binary file file.jpg matches – January Oct 9 '12 at 8:49
  • 1
    @January When a binary file is read as text, it often has extremely long "lines" (because a character or character sequence that would be interpreted to designate the end of a line may not appear for a long time, or ever). Depending on the way a text search utility is implemented, this could cause performance problems if each "line" is read fully into memory and then checked to see if it matches the search string (which is a reasonable way for grep to be coded, though I don't know if Ubuntu's grep is written that way). – Eliah Kagan Oct 9 '12 at 9:30
  • 1
    "grep -i" for case insensitive search – Czarek Tomczak May 24 '13 at 15:32
  • 3
    There should be a * after the final slash in the path or grep does not appear to do any work in 14.04 – DavidScherer May 19 '16 at 13:35
20

You can use regexxer it is a great GUI search/replace tool for regular expressions.

you can download by:

sudo apt-get install regexxer

enter image description here

  • it is super fast, but the issues i have with this application are: 1. it does not have a readonly mode, so I don't accidentally replace or delete anything 2. it shows the text, but it will not move to the specific line that the pattern has matched. (I scrolled around 2000 lines of code to find what I was after after changing the color to bright red!) – Mehrad Mahmoudian Sep 26 '17 at 10:58
6

Try Recoll, best GUI one I ever used. To install recoll in all currently supported versions of Ubuntu open the terminal and type:

sudo apt install recoll

It needs some time to index the files first (you can define blacklist path or extensions or mime).

  • I can confirm that Recoll is completely another world with respect to gnome-search-tool or search-monkey. It uses Xapian, so it's able to inspect and index word documents (both .doc and .docx), pdf files, mail folders, etc. – Avio Mar 22 '17 at 10:51
  • Uh, it's available through deb packaging (sudo apt install recoll) and it does its job where even grep fails, e.g. with .docx documents that are compressed with pkzip compression. – Avio Mar 22 '17 at 10:56
  • note that recoll requires building index first. – Yrogirg Sep 18 at 1:40
5

You can use the grep command from terminal:

grep -r string *

This command will find all occurrences of "string" in all the files under the current directory (or subdrectories).

For hidden files, you can use:

grep -r string ..

2

Unfortunately grep does a very poor job of searching inside Word (.doc) files, but you can pipe catdoc output into grep. I'm no programmer but this little script works well for me:

#!/bin/bash
export GREP_OPTIONS='--color=auto'
echo -e "\n
Welcome to scandocs. This will search .doc (NOT .docx) files in this directory for a given string. \n
Type in the text string you want to find... \n"
read response
find . -name "*.doc" | 
while read i; do catdoc "$i" | 
grep -iH --label="$i" "$response"; done

All improvements and suggestions welcome!

  • 1
    This question was about graphical applications and plain text files. I'm not sure what grep and .doc have to do with the question. – Andrea Corbellini Jan 26 '13 at 14:54
  • Seems OK, see January's detailed answer about grep. – aquaherd Jan 26 '13 at 14:58
2

I've just released a simple tool to do the job. Thought mainly for software developer, it has the (unique?) characteristic of openning several files in the same window. It presents the results in the browser using Ace editor (recomended!) or html textarea. It is a java based tool so it runs in windows as well as in linux.

check it out!

https://sourceforge.net/projects/queacetu.gastona.p/

1

per https://askubuntu.com/a/1141367/47073

You can use mate-search-tool, which is the same thing as gnome-search-tool that was removed. I had problems with searchmonkey, it was missing some results and was slow, do not recommend.

To install mate-search-tool:

sudo apt install mate-utils
mate-search-tool
0

You can use Sublime Text Find in Files option from Find menu to search for strings inside files from a folder.

To Install Sublime Text 3

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

You can also follow this question for other possible ways of installing Sublime on Ubuntu.

To search in all files for a string from a folder in Sublime Text you can follow this question for more clear answers.

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.