在所有Linux手册页中搜索特定的命令或文本
时间:2020-01-09 10:40:40 来源:igfitidea点击:
在KDE或Gnome桌面下,我可以很好地搜索所有手册页中的特定命令或短语。
我通过ssh会话登录到远程服务器。
如何在Linux Shell提示符下搜索所有手册页以查找特定命令?
您需要使用以下命令来搜索手册页:
apropos命令
apropos命令在一组包含系统命令简短描述的数据库文件中搜索关键字,并在屏幕上显示结果。
语法如下:
apropos keyword apropos "string or phrase" apropos -s 1 delete
apropos命令示例
要搜索与比较操作有关的命令/功能,请执行:
$ apropos compare
输出示例:
[ (1) - check file types and compare values bcmp (3) - compare byte sequences bzcmp (1) - compare bzip2 compressed files bzdiff (1) - compare bzip2 compressed files cmp (1) - compare two files byte by byte comm (1) - compare two sorted files line by line compare (1) - mathematically and visually annotate the difference between an image and its reconstruction. diff (1) - compare files line by line diff3 (1) - compare three files line by line git-diff-files (1) - Compares files in the working tree and the index git-diff-index (1) - Compares content and mode of blobs between the index and repository git-diff-tree (1) - Compares the content and mode of blobs found via two tree objects infocmp (1) - compare or print out terminfo descriptions mcomp (1) - Compares two files using mtools memcmp (3) - compare memory areas msgcmp (1) - compare message catalog and template ndiff (1) - Utility to compare the results of Nmap scans ntfscmp (8) - compare two NTFS filesystems and tell the differences pthread_equal (3) - compare thread IDs strcasecmp (3) - compare two strings ignoring case strcmp (3) - compare two strings strcoll (3) - compare two strings using the current locale strncasecmp (3) - compare two strings ignoring case strncmp (3) - compare two strings strverscmp (3) - compare two version strings test (1) - check file types and compare values wcscasecmp (3) - compare two wide-character strings, ignoring case wcscmp (3) - compare two wide-character strings wcsncasecmp (3) - compare two fixed-size wide-character strings, ignoring case wcsncmp (3) - compare two fixed-size wide-character strings wmemcmp (3) - compare two arrays of wide-characters xzcmp (1) - compare compressed files xzdiff (1) - compare compressed files zcmp (1) - compare compressed files zdiff (1) - compare compressed files
搜索字符串
搜索命令以删除文件,执行:
$ apropos "remove file"
输出示例:
rm (1) - remove files or directorie
手册页中的搜索特定部分
要仅搜索给定的手册部分,请使用-s选项:
apropos -s 1 compare
输出示例:
[ (1) - check file types and compare values bzcmp (1) - compare bzip2 compressed files bzdiff (1) - compare bzip2 compressed files cmp (1) - compare two files byte by byte comm (1) - compare two sorted files line by line compare (1) - mathematically and visually annotate the difference between an image and its reconstruction. diff (1) - compare files line by line diff3 (1) - compare three files line by line git-diff-files (1) - Compares files in the working tree and the index git-diff-index (1) - Compares content and mode of blobs between the index and repository git-diff-tree (1) - Compares the content and mode of blobs found via two tree objects infocmp (1) - compare or print out terminfo descriptions mcomp (1) - Compares two files using mtools msgcmp (1) - compare message catalog and template ndiff (1) - Utility to compare the results of Nmap scans test (1) - check file types and compare values xzcmp (1) - compare compressed files xzdiff (1) - compare compressed files zcmp (1) - compare compressed files zdiff (1) - compare compressed files
基于正则表达式的搜索
您可以使用-r选项强制apropos将每个关键字解释为正则表达式:
$ apropos -r scanf
输出示例:
fscanf (3) - input format conversion scanf (3) - input format conversion sscanf (3) - input format conversion Video::DVDRip::CPAN::Scanf (3pm) - emulate sscanf() of the C library vfscanf (3) - input format conversion vscanf (3) - input format conversion vsscanf (3) - input format conversion
man -K命令
-K选项传递给man命令,以在所有手册页中搜索指定的字符串。
语法如下:
man -K keyword man -K "string or phrase"
在所有手册页中搜索fopen字,执行:
$ man -K "fopen"
输出:
/usr/share/man/en/man3/fclose.3.gz? [ynq]
输入y打开/显示手册页,输入n继续搜索,输入q退出搜索。
这是蛮力搜索,可能会花费一些时间。
因此,使用以下语法来指定手册页部分(1-7)有助于:
$ man -s 3 -K "open"
或者
$ man -s 8 -K "user"
请注意,上述命令也可以与其他UNIX和* BSD一起使用,例如oses