当前位置: 技术问答>linux和unix
特简单的问题(在线等待)
来源: 互联网 发布时间:2014-12-05
本文导语: 请问我要在一大堆文件中寻找一特定的字符串,该怎么写命令,请详细一点,兄弟先谢了 | grep "特定字符" file1 file2 file3 .... | grep 字符串 文件名 其中文件名可以用通配...
请问我要在一大堆文件中寻找一特定的字符串,该怎么写命令,请详细一点,兄弟先谢了
|
grep "特定字符" file1 file2 file3 ....
|
grep 字符串 文件名
其中文件名可以用通配符。
其中文件名可以用通配符。
|
如果有特殊符号,模式字符串最好加上引号
|
-h, --no-filename
Suppress the prefixing of filenames on output when
multiple files are searched.
--help Output a brief help message.
-I Process a binary file as if it did not contain
matching data; this is equivalent to the --binary-
files=without-match option.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and
the input files.
-L, --files-without-match
Suppress normal output; instead print the name of
each input file from which no output would normally
have been printed. The scanning will stop on the
first match.
-l, --files-with-matches
Suppress normal output; instead print the name of
each input file from which output would normally
have been printed. The scanning will stop on the
first match.
--mmap If possible, use the mmap(2) system call to read
input, instead of the default read(2) system call.
In some situations, --mmap yields better perfor
mance. However, --mmap can cause undefined behav
ior (including core dumps) if an input file shrinks
while grep is operating, or if an I/O error occurs.
-n, --line-number
Prefix each line of output with the line number
within its input file.
-q, --quiet, --silent
Quiet; suppress normal output. The scanning will
stop on the first match. Also see the -s or --no-
messages option below.
-r, --recursive
Read all files under each directory, recursively;
this is equivalent to the -d recurse option.
-s, --no-messages
Suppress error messages about nonexistent or
unreadable files. Portability note: unlike GNU
grep, traditional grep did not conform to POSIX.2,
because traditional grep lacked a -q option and its
-s option behaved like GNU grep's -q option. Shell
scripts intended to be portable to traditional grep
should avoid both -q and -s and should redirect
output to /dev/null instead.
-U, --binary
Treat the file(s) as binary. By default, under MS-
DOS and MS-Windows, grep guesses the file type by
looking at the contents of the first 32KB read from
the file. If grep decides the file is a text file,
it strips the CR characters from the original file
contents (to make regular expressions with ^ and $
work correctly). Specifying -U overrules this
guesswork, causing all files to be read and passed
to the matching mechanism verbatim; if the file is
a text file with CR/LF pairs at the end of each
line, this will cause some regular expressions to
fail. This option has no effect on platforms other
than MS-DOS and MS-Windows.
-u, --unix-byte-offsets
Report Unix-style byte offsets. This switch causes
grep to report byte offsets as if the file were
Unix-style text file, i.e. with CR characters
stripped off. This will produce results identical
to running grep on a Unix machine. This option has
no effect unless -b option is also used; it has no
effect on platforms other than MS-DOS and MS-Win
dows.
-V, --version
Print the version number of grep to standard error.
This version number should be included in all bug
reports (see below).
-v, --invert-match
Invert the sense of matching, to select non-match
ing lines.
-w, --word-regexp
Select only those lines containing matches that
form whole words. The test is that the matching
substring must either be at the beginning of the
character. Word-constituent characters are let
ters, digits, and the underscore.ther at the end of
the line or followed by a non-word constituent
-x, --line-regexp
Select only those matches that exactly match the
whole line.
-y Obsolete synonym for -i.
-Z, --null
Output a zero byte (the ASCII NUL character)
instead of the character that normally follows a
file name. For example, grep -lZ outputs a zero
byte after each file name instead of the usual new
line. This option makes the output unambiguous,
even in the presence of file names containing
unusual characters like newlines. This option can
be used with commands like find -print0, perl -0,
sort -z, and xargs -0 to process arbitrary file
names, even those that contain newline characters.
|
for example:
if you want find "abcdef" in all the files in current directory , you can type in the shell :
grep "abcdef" "./*"
if you want find "abcdef" in all the files in current directory , you can type in the shell :
grep "abcdef" "./*"