0

I am running a command to search certain string in a folder but it halts when it encounters file with no extension.

sudo grep -rlvF "peter.dickson@" /var/www

how I can overcome this?

As per the suggestion in the comment I have run this command

pawan@server1:~$ sudo find /var/www -type p
[sudo] password for pawan: 
pawan@server1:~$ 

But I didn't get any output from this command.

5
  • Please edit your question and give us more details. Extensions are completely irrelevant to grep (and 99.9% of all Linux programs) so that's not the problem. Are you sure it halts and isn't simply taking a long time? Can you reproduce it with a smaller file? The command you show will print all lines of all files in /var/www that don't match peter.dickson@. That could take ages if you have a deep directory tree with many, large files.
    – terdon
    Mar 20 '16 at 18:37
  • I am not sure but it halts at a specific location for hours, whereas that is a small file on check - /var/www/lions322c2.org/run/motd
    – Joshi
    Mar 20 '16 at 19:58
  • how do you know it halts there? And, assuming it does, is that a regular file? Could it be a named pipe instead?
    – terdon
    Mar 20 '16 at 20:20
  • I am running the command as verbose - the screen continuously progress, but coming at this line /var/www/lions322c2.org/run/motd it just halts and there is no progress after that even for 14 hours. It is a normal file, I can paste the contents of the file if you want to have a look at it?
    – Joshi
    Mar 21 '16 at 9:13
  • 1
    There is no "verbose" flag for grep. If you mean -v, that inverses the match and prints lines that don't match the pattern, as I said in my previous comment. That said, if you see that file name, then that file has already been processed and your problem occurs with the next one. I am pretty sure that your issue is that you are grepping through a named pipe. That will hang indefinitely. Please edit your question and show the output of find /var/www -type p.
    – terdon
    Mar 21 '16 at 9:16
1

It seems that what you want is

find /var/www -type f | xargs grep -l "peter\.dickson@"

The effect of xargs is that The outputs of find (all normal files under the path you provide) are passed as final arguments to the grep command (after the initial arguments provided).

Edit: the period is a special character for grep, so it should be escaped by preceding it with a backslash, as shown.

2
  • 1
    OP also used v and F. Also notice that find has a handy -exec switch which takes out the need and the risks of piping the output to another command: find /var/www -type f -exec grep -lvF "peter.dickson@" {} + (or if you really don't want to use -exec: find /var/www -type f | xargs grep -lvF "peter.dickson@")
    – kos
    Mar 22 '16 at 16:57
  • I assume that the OP wanted to do what he described in his question, that is, find lines matching the string, not lines not matching it. So -v is an error. If you look up what -F does, you'll probably agree that it's not required here either. Mar 22 '16 at 17: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.