Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
when i use this command it takes 2 second to find right file (i have 30 files under this directory)
I want fast search by using any command per your recommendation. I use "find" and "grep" so far and it's not fast enough because php function use grep to identify the word on result page. Is there any blazing fast system where i can use any command or software i can install anything on my server as long as it works fast i also tried ramdisk but no difference any suggestion from linux gurus highly appriciated.
(need to be exact match only -Rc works in 1 sec however doesn't come with exact match "--word regexp" catch exact match but it takes 2-3 second to result i been trying to solve this problem for 3 days
]$ time (find language/latest/ -type f -name "*.txt" -print0|xargs -0 -iX grep -Hc "direzione" 'X')
language/latest/swe.txt:0
language/latest/ltz.txt:0
language/latest/lit.txt:0
language/latest/bos.txt:0
language/latest/lav.txt:0
language/latest/som.txt:0
language/latest/deu.txt:0
language/latest/spa.txt:0
language/latest/azj.txt:0
language/latest/ita.txt:1
real 0m0.023s
user 0m0.002s
sys 0m0.024s
when you can
Code:
]$ time grep -c "direzione" -r language/latest/
language/latest/swe.txt:0
language/latest/ltz.txt:0
language/latest/lit.txt:0
language/latest/bos.txt:0
language/latest/lav.txt:0
language/latest/som.txt:0
language/latest/deu.txt:0
language/latest/spa.txt:0
language/latest/azj.txt:0
language/latest/ita.txt:1
real 0m0.004s
user 0m0.000s
sys 0m0.003s
and I agree indexing probably makes more sense if you query often and a lot. Either find something that works with Nginx or find something that offers an independent abstraction layer.
I won't guarantee this will work in all cases, but none of the examples so far perform a parallel search - and serial file searching always takes longer:
Code:
find language/latest/ -type f -name "*.txt" -print|
(
while read F do
grep -Hc "direzione" $F &
done
wait
) >>log.file
--- note, not syntax checked...
This should provide the same list, though the order of lines will be interleaved.
The goal here is to do all the searching in parallel (hence the grep ... &). This should work as long as you don't have many thousands of files to search (you will use up your process limit quota).
The system time should increase due to context switches, but the elapsed time should decrease even more.
i found -P very fast but still far from my expectation
You are looking for a plain string, so you can use -F (it only handles plain strings so it's probably the fastest mode; although it seems like IO could be the limiting factor here, in which case there won't be any measurable improvement).
Also, from your output it appears that you never have more than 1 match per file, maybe you could use -l (--files-with-matches) instead of -c (--count)?
Quote:
Originally Posted by jpollard
I won't guarantee this will work in all cases, but none of the examples so far perform a parallel search
I think the xargs -n1 -P8 one is parallel. It might be better to try with a bit less parallelism, xargs -n5 -P2.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.