LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-07-2014, 11:10 AM   #1
CamTheSaxMan
Member
 
Registered: Nov 2013
Distribution: Linux Mint 13 Cinnamon Edition 64-bit, Windows 7 Home Premium SP1 64-bit, Arch Linux 32-bit
Posts: 161

Rep: Reputation: 9
grep -i is EXTREMELY slow!


I'm trying to search for a case-insensitive string in a directory, but grep -i is either incredibly slow or hangs. I tried to search for a simple string "document" in my home folder, but the search was still going after a whole HOUR! so I just gave up. Why is it so slow? Are there any workarounds?
 
Old 02-07-2014, 11:37 AM   #2
Vrajgh
Member
 
Registered: Aug 2005
Posts: 68

Rep: Reputation: 33
Can you provide the complete command used please?

If you were (for example) to use

Code:
grep -i foo
then grep would read from stdin (keyboard) rather than the directory and will never finish until interrupted. To search the directory you need to give it a list of files to search, eg

Code:
grep -i foo *
 
Old 02-07-2014, 12:37 PM   #3
CamTheSaxMan
Member
 
Registered: Nov 2013
Distribution: Linux Mint 13 Cinnamon Edition 64-bit, Windows 7 Home Premium SP1 64-bit, Arch Linux 32-bit
Posts: 161

Original Poster
Rep: Reputation: 9
Yes, that's what I did. I typed:
Code:
grep -i -r documents *
and it just sits there. I did a Google search and found that this is a common issue. fgrep actually worked for me, though I don't really know what the difference between fgrep and grep is.
 
Old 02-07-2014, 03:49 PM   #4
Tux1000
LQ Newbie
 
Registered: Feb 2014
Posts: 10

Rep: Reputation: Disabled
If you tell grep to search a string in a file in a directory with or without subdirectories and there are many, many files, it will take some time of course and it may appeared to be hung but maybe not.

I did a test run on one of my directories where it has subdirectories and many files. For example:

Code:
time grep -ir -l "How do I backup a LUKS header" backup/*
backup/docs-and-media/linux-related/cryptsetuo faq

real    2m18.305s
user    2m17.685s
I use the time command to tell me how long it takes to the complete the search. It took 2m and 18 secs. The -l option tells grep to list the file the string was found in. BTW, the time command is not necessary for doing grep searches, it's used here just to demonstrate that grep can take some time on searching many files. Anyway, it found the string in backup/docs-and-media/linux-related/cryptsetuo faq

There is a another command called ack. It's like grep on steroids and very fast.

Code:
time ack -ai -l "How do I backup a LUKS header" backup/*
backup/docs-and-media/linux-related/cryptsetuo faq

real    0m19.791s
user    0m19.265s
sys     0m0.489s
Here is the same search on the backup directory, but the search is done faster by using ack, for a total of 19secs to complete.

Give ack a try.

Last edited by Tux1000; 02-07-2014 at 04:07 PM.
 
Old 02-08-2014, 02:02 PM   #5
e5150
Member
 
Registered: Oct 2005
Location: Sweden
Distribution: Slackware and Alpine
Posts: 132

Rep: Reputation: 100Reputation: 100
There are a few things you can do which might speed up greping. If you're only interested in text files that matches your search word, use the -I switch (according to man page: "-I Process a binary file as if it did not contain matching data"). Also, case insensitive searches are particularly slow when using a UTF-8 locale. If your search words only contains ascii-compatible characters (A-Z, a-z, 0-9, (),./-#! and such) try: `LC_CTYPE=C grep -i -r documents *`.
 
Old 02-08-2014, 05:54 PM   #6
CamTheSaxMan
Member
 
Registered: Nov 2013
Distribution: Linux Mint 13 Cinnamon Edition 64-bit, Windows 7 Home Premium SP1 64-bit, Arch Linux 32-bit
Posts: 161

Original Poster
Rep: Reputation: 9
Odd thing is that grep -i is not slow on Linux Mint. I do have a higher-spec computer on Mint, so that may be the cause.
 
  


Reply

Tags
grep, search, slow



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IBM T42 "Extremely, EXTREMELY Slow" alwayslearning Linux - Laptop and Netbook 5 10-11-2009 03:34 AM
extremely slow runlevel 5 axelmang Linux - General 12 11-14-2008 05:00 AM
Wine extremely slow!!!!!!!!!!!! augu2000 Linux - Software 3 11-01-2005 06:18 PM
sdl games are slow extremely slow linksocc Linux - Software 7 01-17-2004 03:53 PM
KDE extremely slow? totalcommand Linux - Newbie 1 08-18-2001 10:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration