开始使用免费开始使用

如何获取某个命令的帮助?

为了了解命令的作用,过去人们常用 man 命令("manual" 的缩写)。例如,运行 man head 会显示如下信息:

HEAD(1)               BSD General Commands Manual              HEAD(1)

NAME
     head -- display first lines of a file

SYNOPSIS
     head [-n count | -c bytes] [file ...]

DESCRIPTION
     This filter displays the first count lines or bytes of each of
     the specified files, or of the standard input if no files are
     specified.  If count is omitted it defaults to 10.

     If more than a single file is specified, each file is preceded by
     a header consisting of the string ``==> XXX <=='' where ``XXX''
     is the name of the file.

SEE ALSO
     tail(1)

man 会自动调用 less,因此您可能需要按空格键翻页,并使用 :q 退出。

NAME 下的一行描述会简要说明该命令的功能,而 SYNOPSIS 下的摘要列出了它支持的所有标志。任何可选项会用方括号 [...] 表示,二选一的选项用 | 分隔,可以重复的内容用 ... 表示。所以,head 的手册页告诉您:您可以用 -n 提供行数,或用 -c 提供字节数,并且可以提供任意数量的文件名。

Unix 手册的问题在于,您必须先知道要找什么。如果不清楚,您可以搜索 Stack Overflow、在 DataCamp 的 Slack 频道提问,或查看您已掌握命令的 SEE ALSO 部分。

本练习是课程的一部分

Shell 入门

查看课程

动手互动练习

通过我们的互动练习之一,将理论转化为实践

开始练习