Linux [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Linux [Electronic resources] - نسخه متنی

Janet Valade

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


The grep Command


The grep command is so beloved by Linux users that it has its own t-shirts. The grep command finds files that have specified contents and outputs each line that it finds. The general format for the grep command is:

grep

options pattern files

where:

  • pattern specifies the text string to search for.

    pattern can be a literal string, such as abc or xxx.

    pattern can also be a regular expression, a pattern to be matched, such as any uppercase character or any word that begins with

    Q . Regular expressions are discussed in Appendix A.

  • files specifies the files to search for the string.

    files can specify filenames (using wildcards if needed) or a directory.


For example, the following is a simple grep command with its output:

grep "Mary Poppins" *
file1.txt:I like Mary Poppins!
file7.txt:Mary Poppins is a great movie.

The command looks in all the files in the current directory for the string, Mary Poppins. Lines containing the search string display, with the filename prepended. You can use a path (such as /home/janet) instead of *, to specify a directory and all the files in that directory are searched.

The grep command has many options, some of which are shown in Table 7-6.

Table 7-6. Options for the grep Command

Option

What it does

-c

Output the number of lines found, rather than the lines themselves.

-i

Ignore upper- and lowercase when matching.

-l

Output the names of files with matches, rather than the actual lines.

-n

Include the line number of the match: file1.txt:16:Text on line.

-r

Check all subdirectories in the specified directory.

-v

Output all lines that don't match.

-x

Output a line only when the pattern matches the entire line.


    / 357