[Courses][Linux comands] Finding things with locate, find, and
grep
Conor Daly
c.daly at met.ie
Mon Feb 23 10:10:42 EST 2004
On Thu, Feb 19, 2004 at 10:17:34AM +0100 or thereabouts, Dan Richter wrote:
>
> In addition to -n (line number), you can use -<number>, which causes
> grep to output <number> lines before and after the match:
>
> grep -n -3 'Free Software Foundation' GPL.txt
>
> GNU grep allows you to use -A <num> and -B <num> to specify
> (respectively) the number of lines before and after the match to output,
> but I suspect that this behavior is less portable.
Alas, it appears that 'grep -<number>' is itself non portable. SunOS 5.8
grep gives:
nu:cdaly>grep -3 test maxfall.tar
grep: illegal option -- 3
Usage: grep -hblcnsviw pattern file . . .
But of course, this is about _linux_ commands and it's so cool that everyone
else should do it...
Incidentally, Carla mentioned wildcards with find. It's important to note
that the wildcard _must_ be inside single quotes (eg find . -name 'arrow*').
This protects the wildcard from expansion by the shell before find gets the
pattern. Without the quotes, the command will expand to "find . -name
arrow.png" 'cos you had a file called 'arrow.png' in your home dir and
nothing else will be found.
Conor
--
Conor Daly, Please avoid sending me
Met Eireann, Glasnevin Hill, Word or PowerPoint attachments.
Dublin 9, Ireland http://www.fsf.org/philosophy/no-word-attachments.html
Ph +3531 8064276 Fax +3531 8064247
**********************************************************************
This e-mail and any files transmitted with it are confidential
and intended solely for the addressee. If you have received
this email in error please notify the sender.
This e-mail message has also been scanned for the
presence of computer viruses.
**********************************************************************
More information about the Courses
mailing list