22. 命令: grep

‘grep‘命令搜索指定文件中包含给定字符串或者单词的行。举例搜索‘/etc/passwd‘文件中的‘tecmint'

  1. root@tecmint:~# grep tecmint /etc/passwd 
  2. tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash 

使用’-i'选项将忽略大小写。

  1. root@tecmint:~# grep -i TECMINT /etc/passwd 
  2. tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash 

使用’-r'选项递归搜索所有自目录下包含字符串 “127.0.0.1“.的行。

  1. root@tecmint:~# grep -r "127.0.0.1" /etc/ 
  2. /etc/vlc/lua/http/.hosts:127.0.0.1 
  3. /etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1" 
  4. /etc/mysql/my.cnf:bind-address      = 127.0.0.1 
  5. /etc/apache2/mods-available/status.conf:    Allow from 127.0.0.1 ::1 
  6. /etc/apache2/mods-available/ldap.conf:    Allow from 127.0.0.1 ::1 
  7. /etc/apache2/mods-available/info.conf:    Allow from 127.0.0.1 ::1 
  8. /etc/apache2/mods-available/proxy_balancer.conf:#    Allow from 127.0.0.1 ::1 
  9. /etc/security/access.conf:#+ : root : 127.0.0.1 
  10. /etc/dhcp/dhclient.conf:#prepend domain-name-servers 127.0.0.1; 
  11. /etc/dhcp/dhclient.conf:#  option domain-name-servers 127.0.0.1; 
  12. /etc/init/network-interface.conf:   ifconfig lo 127.0.0.1 up || true 
  13. /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). 
  14. /etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost|127.0.0.1 
  15. /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). 
  16. /etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost|127.0.0.1 
  17. /etc/hosts:127.0.0.1    localhost 

注意:您还可以使用以下选项:

  • -w 搜索单词 (egrep -w ‘word1|word2‘ /path/to/file).
  • -c 用于统计满足要求的行 (i.e., total number of times the pattern matched) (grep -c ‘word‘ /path/to/file).
  • –color 彩色输出 (grep –color server /etc/passwd).

23. 命令: man

‘man‘是系统帮助页。Man提供命令所有选项及用法的在线文档。几乎所有的命令都有它们的帮助页,例如:

  1. root@tecmint:~# man man 
  2. MAN(1)                                                               Manual pager utils                                                              MAN(1) 
  3. NAME 
  4. man - an interface to the on-line reference manuals 
  5. SYNOPSIS 
  6. man  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R  encoding]  [-L  locale]  [-m  system[,...]]  [-M  path]  [-S list] [-e extension] [-i|-I] 
  7. [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification]  [-p 
  8. string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ... 
  9. man -k [apropos options] regexp ... 
  10. man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ... 
  11. man -f [whatis options] page ... 
  12. man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] 
  13. [-H[browser]] [-X[dpi]] [-Z] file ... 
  14. man -w|-W [-C file] [-d] [-D] page ... 
  15. man -c [-C file] [-d] [-D] page ... 
  16. man [-hV] 

上面是man命令的系统帮助页,类似的有cat和ls的帮助页。

注意:系统帮助页是为了命令的使用和学习而设计的。


相关内容