3.10 读取命令的描述

whatis

本章前面介绍过man命令的-f选项,它可以将在man page中找到的命令描述打印到屏幕上。如果你还记得man –f能够提供这些信息,你真的很棒!不过,要记住whatis命令则要容易得多,它也能做同样的事:显示命令的man page的描述。

  1. $ man -f ls
  2. ls (1) - list directory contents
  3. $ whatis ls
  4. ls (1) - list directory contents

whatis命令还支持正则表达式和通配符。要用通配符搜索man数据库,可以使用-w选项(或--wildcard)。

  1. $ whatis -w ls*
  2. ls (1) - list directory contents
  3. lsb (8) - Linux Standard Base support for Debian
  4. lshal (1) - List devices and their properties
  5. lshw (1) - list hardware
  6. lskat (6) - Lieutnant Skat card game for KDE
  7. [Listing condensed due to length]

与不使用选项的whatis命令相比,使用通配符可能会让搜索速度稍微慢一些,但是对于今天运行速度越来越快的计算机来说,这种影响是微不足道的,所以大可不必为此担忧。

正则表达式可以和-r(或--regex)选项一起使用。

  1. $ whatis -r ^rm.*
  2. rm (1) - remove files or directories
  3. rmail (8) - handle remote mail received via uucp
  4. rmdir (1) - remove empty directories
  5. rmt (8) - remote magtape protocol module

提示 本书没有详细介绍正则表达式,但是可以阅读由Ben Forta撰写的Sams Teach Yourself Regular Expressions in 10 Minutes(ISBN: 0672325667)来获取更多信息。

虽然使用正则表达式可能会让whatis命令的响应速度变慢,但是你可能根本不会注意到这个问题。

whatis命令便于记忆(至少要比man –f更容易),而且它还能快速返回一些重要信息,因此一定要记住它。