服务器 频道

Solaris的中文命令参考手册之二

  【IT168 服务器学院】find
  #find . -name test.txt //搜索当前目录
  #find dir -name test.txt
  #find / -name test.txt
  #find /export/home -name test.txt
  #find ~ -name ‘*tif'' //用户的主目录
  #find /export -name core -exec rm {} \ //搜索core文件并删除它们
  #find dir -type d //文件类型
  #find /export -type d -name test //文件夹名为test
  #find /export -size +400 //文件大于400块的512byte =1 blocks
  #find /export -name test.txt -exec rm {} \; //查找并删除
  #find /export -name test.txt -ok rm {} \; //交互模式删除 y
  #find /export -user keven //按用户查找
  #find / -user UID -exec rm{} \; //查找该用户的文件并删除
  #find / -name pfile -print>find.txt 2>null.txt&
  //找到则放入find.txt,否则就放到null.txt 程序在后台运行
  
  # find /export -name tex.txt -exec rm {} \; //{} \中间有一个空格
  $ find ~ -name ''*es'' //es的前面为任意字符
  
  
  搜索表达式 意义 定义
  name filename 文件名 搜索所有匹配的给定的文件,可以接受元字符(如? *)
  type filetype 文件类型 搜索匹配给定文件类型的文件(d为目录)
  mtime [+|-]n 修改的时间 搜索所有修改时间或者大于,或小于给定时间的文件
  atime[+|-]n 访问的时间 搜索所有访问时间或者大于,或者小于给定时间的文件
  user loginid -group groupid 用户ID和属组ID 搜索所有匹配登陆ID的所有者或属组ID的文件
  perm mode 权限 搜索所有匹配给定权限的文件(只允许八进制模式)
  size[+|-]n[c] 搜索所有大小或者大于,小于n的文件,n以512字节每块计算,如果后面有ac,则以字符(字节)计算
  -print 基将搜索结果输出到标准输出。该结果是一个全路径名的文件名 列表
  
  -exec command{}\; exec选项必须通过\;来终止;这样使得find命令可以应用于指定命令中搜索准则中给出的每个文件
  -ok command{}\; -exec的交互格式.这个选项用于要求来自用户的输入命令.如 rm -i
  -ls 使用长列表格式打印当前路径.这个表达式最常用于链接一个输出,把它重定向到一个文件中,以便稍后进行检查
  
  
  
  
  #grep root /etc/passwd //在passwd中查找root
  #grep -i root /etc/passwd //忽略大小写
  #grep -v root /etc/passwd //显示除了含有root的行
  # grep -c root group //统计有多少行
  10
  
  # grep -l root passwd group hosts //查找文件中包含root的文件
  passwd
  group
  
  
  
  正则表达式 功能 例子 结果
  .(dot) 匹配任意字符可以多次使用,类似ls命令 grep chap.. file 显示所有包含chap,且之后还有两个字符的行
  *(asterisk) 在模式上匹配0个或多个字符 grep chap* file 显示所有包含chap,且之后可以是任意字符
  \(back slash) 告诉shell按照字面意思理解\之后的特殊字符 grep dollar\* file 显示所有包含dollar*的行./告诉shell按照字面意思理解*,而不是通配符
  ^ (caret) 匹配所有以指定模式打头的所有行 grep ^name file 显示所有以Name开头的行
  $ 匹配所有以指定模式结尾的行 grep $800 file 显示所有以800结尾的行
  [] 匹配模式中的一个字符 grep [64.128] 显示所有包含64MB或128MB的行
  -i 忽略大小写
  -v 反包含.除了该字符串之外的行
  
  
  egrep
  # egrep ''N(e|o)'' /etc/passwd //查找以字母大N开头后面接e 或者o
  listen:x:37:4:Network Admin:/usr/net/nls:
  nobody:x:60001:60001:Nobody:/:
  noaccess:x:60002:60002:No Access User:/:
  nobody4:x:65534:65534:SunOS 4.x Nobody:/:
  
  
  $ egrep ''(Network|uucp) Admin'' /etc/passwd
  uucp:x:5:5:uucp Admin:/usr/lib/uucp:
  nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
  listen:x:37:4:Network Admin:/usr/net/nls:
  
  
  
0
相关文章