Find a word.
Hi All,
I want to find all the files in my system that contains a specific word(exact match). i wote this command but it didnt work out: find / -type f -exec fgrep -l "my_word" {} \;>/tmp/my_file my_file-should contain a list of files that contains the word that i'm looking for. hope someone can help........ Thanks, :confused: |
I haven't tried this, but I think you need to put the {} and ; in quotes, like this:
find / -type f -exec fgrep -l "my_word" '{} ';' > /tmp/my_file The quotes, I think, prevent them from being interpreted literally by find (or maybe by fgrep) The Linux Cookbook has a nice section on finding files, which is where I got this info from. Check it out if you haven't already :) |
Your find statement works correctly. You probably need to setup a controlled environment to test. ie. search a smaller directory with files that guarantee a hit.
|
Just something you might want to consider since you plan for it to search your whole filesystem which could be a lot of files.
The find command is gonna start a fgrep process for each file it finds and then look through it and then the fgrep process will close again. It's gonna repeat this till it's gone through each file it's found. If you use the xargs command then a whole list of files can be sent to one fgrep process which reduces the overhead of having to stop and start so many processes. Ofcourse you get the added overhead of xargs and the pipe, but that's a lot less. The nice thing about *nix is that it's good with handling starting and stopping of processes so you don't notice it that much. But if you try to run the same thing on Windows NT with cygwin then you really start noticing the difference, if it doesn't lock up on you in the mean time. Anyways here is what the command with xargs would look like, which in my opinion also looks a lot simpler: find / -type f | xargs fgrep -l "my_word" > /tmp/my_file |
In my opinion, there's an even easier way to use find to find a filename that you are looking for:
Code:
find / -type f -name my_word contain the string my_word: Code:
find / -type f -name \*my_word\* |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 04:56 AM. |