bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#56453: Bug reports


From: Gary Johnson
Subject: bug#56453: Bug reports
Date: Fri, 8 Jul 2022 10:32:04 -0700
User-agent: Mutt/1.5.20 (2009-06-14)

On 2022-07-08, GUI via Bug reports for GNU grep wrote:
> I'm a beginner for Linux.

> Today, when I was learning the grep command, I used the man
> command to check its manual and found a suspicious point.In its
> DESCRIPTION,it says "grep  searches  for  PATTERN  in  each  FILE.
> A FILE of “-” stands for standard input.  If no FILE is given,
> recursive searches examine the working directory, and nonrecursive
> searches read standard input.  By default, grep prints the
> matching lines. In addition, the variant programs egrep and fgrep
> are the  same  as  grep -E  and  grep -F,  respectively.   These
> variants  are deprecated, but are provided for backward
> compatibility."

> I think there are something wrong with the sentence 'If no FILE is
> given, recursive searches examine the working directory, and
> nonrecursive searches read standard input. ' . Pay attention to
> the 'and' in "recursive searches examine the working directory,
> and nonrecursive searches read standard input".When I use the grep
> command,such as this:

The sentence in the manual is correct as written.  Note that
a search can be recursive or nonrecursive, but not both.

> [root@localhost ~]# grep Download dwad dawdwa Downloads Downloads ^C
> [root@localhost ~]# 

> From this result,we can see that if no file is given, nonrecursive
> searches read standard input instead of that rescursive searches
> examine the working directory.

As that command appears in your post, a file _is_ given.  In fact,
four file names are given; the last two are the same file.

    grep Download dwad dawdwa Downloads Downloads

searches for the pattern Download in the files dwad, dawdwa,
Downloads and Downloads.  The search is nonrecursive since the
command does not include either the -r nor -R options are given.

The results indicate that the string Download is not found in any of
those files.  I don't know what the ^C at the end of your command
means.  ^C (Ctrl-C) normally kills the current command, but I don't
think you want to do that here.

> As we known, the working directory is ~,whose subdirectories have
> 'Downloads'.So when you type grep Download on  terminal, you
> should see 'Downloads' under the current folder ~.

I think you misunderstand what grep does.  Grep searches for
a pattern in the contents of files, or in the contents of its
standard input.  It does not search for a pattern in file names.

If you want to search for a pattern in the names of the files in
your working directory, use this pipeline instead:

    ls | grep Download

The ls command will list all the file names in your working
directory and grep will search that list for the string Download.

> I don't know why or There is something wrong with the description
> of grep in the manual.

The description is fine.  You just need a little more experience
with Linux commands and with interpreting the manual pages.  Their
English is usually correct, but not always clear.

Regards,
Gary






reply via email to

[Prev in Thread] Current Thread [Next in Thread]