HarrySun

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

使用Linux,有两个命令的基本用法不得不熟悉,第一个是find,另一个是grep。

find命令(截取):

harry@harry-desktop:~$ grep --h
用法: grep [选项]...模式 [文件]...
在每个文件中查找样式或标准输入。
PATTERN 默认的是一个基本的正则表达式(BRE)。
例: grep -i 'hello world' menu.h main.c

      grep  e$ word.txt

      grep  a[[:blank:]]  words.txt

      grep  Th.[[::space]]  words.txt


正则表达式的选择和解释:
-E, --extended-regexp PATTERN是一个扩展的正则表达式(ERE)
-F, --fixed-strings PATTERN是一套新行分离修复字符串
-G, --basic-regexp PATTERN是一个基本的正则表达式(BRE)
-P, --perl-regexp PATTERN是一个Perl正则表达式
-e, --regexp=PATTERN 使用 PATTERN 来匹配
-f, --file=FILE 从 FILE 来获得 PATTERN
-i, --ignore-case 忽略大小写
-w, --word-regexp 强制 PATTERN 仅匹配整个词
-x, --line-regexp 强制 PATTERN 仅匹配整行
-z, --null-data 结尾为 0 字节而不是新行符的数据行

杂项:
-s,--no-messages 不显示错误信息
-v,--invert-match 选择不匹配的行

输出控制:
-m, --max-count=NUM 在有NUM个匹配后停止
-b, --byte-offset 在输出行的同时打印字节位移
-n, --line-number 在输出行的同时打印行数
--line-buffered flush output on every line
-H, --with-filename print the filename for each match
-h, --no-filename suppress the prefixing filename on output
--label=LABEL print LABEL as filename for standard input
-o, --only-matching show only the part of a line matching PATTERN
-q, --quiet, --silent suppress all normal output
--binary-files=TYPE assume that binary files are TYPE;
TYPE is `binary', `text', or `without-match'
-a, --text 等同于 --binary-files=text
-I 等同于 --binary-files=without-match
-d, --directories=ACTION how to handle directories;
ACTION is `read', `recurse', or `skip'
-D, --devices=ACTION how to handle devices, FIFOs and sockets;
ACTION is `read' or `skip'
-R, -r, --recursive 等同于 --directories=recurse
--include=FILE_PATTERN 只搜索符合FILE_PATTERN型式的文件
--exclude=FILE_PATTERN 跳过名字为FILE_PATTERN的文件或目录
--exclude-from=FILE skip files matching any file pattern from FILE
--exclude-dir=PATTERN directories that match PATTERN will be skipped.
-L, --files-without-match print only names of FILEs containing no match
-l, --files-with-matches print only names of FILEs containing matches
-c, --count print only a count of matching lines per FILE
-T, --initial-tab make tabs line up (if needed)
-Z, --null FILE名字后打印0字节

上下文控制:
-B, --before-context=NUM 打印 NUM 行上文
-A, --after-context=NUM 打印 NUM 行下文
-C, --context=NUM 打印 NUM 行输出上下文
-NUM 与 --context=NUM相同
--color[=WHEN],
--colour[=WHEN] 使用标记来高亮匹配的字符串;
WHEN 可取值为“always”,“never”或“auto”
-U, --binary 不去掉 EOL(MSDOS)处的 CR 字符
-u, --unix-byte-offsets 如果 CR 不在那里(MSDOS),报告偏移值


 

find 命令

find  [path]  [options]   [tests]  [actions]

example:

    find   .  -name  test     -print

   其中[tests]部分可以如下:    

  -user  username

  -type d

     -type f

     -newer otherfile       #比otherfile更新

    

posted on 2011-12-01 11:32  HarrySun  阅读(150)  评论(0)    收藏  举报