Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-23-2009, 05:30 PM   #1
Registered: Dec 2008
Location: Tahiti
Distribution: Kali Linux
Posts: 42

Rep: Reputation: 17
Question grep syntax error?

Hi guys,

I'm studying for LPI, and got to solve this question:

Find out which file contains the following entry:
So far I've tried out using two solutions to list the required files out of the whole system (/):

grep -H -I -i -n -R 'root:x:0:0:root:/root:/bin/bash' / > /var/tmp/output 2> /var/tmp/error
find / -type f | xargs grep -H -I -i -n 'root:x:0:0:root:/root:/bin/bash' > /var/tmp/output 2> /var/tmp/error
The -H and -n options preface each match with the file name and line number of each match, respectively. The -i option ignores case. -I (capital "I") skips binary files.

The problem: both commands doesn't finish.. They hang and I have to kill the processes after 15 minutes...

So, how can I solve it? I am expecting 'probably': /etc/passwd inside /var/tmp/output and a lot of denial permission errors inside /var/tmp/error. Right?

Thanks in advance!
Old 05-23-2009, 05:38 PM   #2
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Why not let the command complete? You're on the right track
Old 05-23-2009, 05:40 PM   #3
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Just lost all that I typed so here is the short version...

The following worked for me (as root)
# grep -Rl 'root:x:0:0:root:/root:/bin/bash' /
and if you want to use find... try this
# find / -type f -exec grep -l 'root:x:0:0:root:/root:/bin/bash' {} \;
Running as root will assure you you san all files on your box.

Hope this helps

Last edited by eco; 05-23-2009 at 05:43 PM. Reason: added find
Old 05-23-2009, 05:44 PM   #4
Gentoo support team
Registered: May 2009
Location: 56N 3W
Distribution: Gentoo
Posts: 178

Rep: Reputation: 40

Reduce the problem space. grep in /etc, not /
Add the options in one at a time.

The grep works properly here but its very slow (I tested on /etc) if you want to process every file on the filesystem maybe 15 min isn't long enough.

The fact the the command runs at all, shows the syntax is correct.


find, grep, xargs

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Need a little help with grep syntax okos Linux - Software 2 01-26-2009 12:50 AM
Command syntax question for grep kaplan71 Linux - Software 4 07-16-2008 03:13 PM
grep CLI syntax: how to find A OR B? Kropotkin Linux - Newbie 3 01-16-2007 10:45 PM
grep script/syntax carriehoff Linux - Newbie 6 08-31-2006 02:13 PM
Grep syntax questions Phaethar Linux - General 4 04-11-2005 10:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:02 AM.

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