1. Learn
  2. /
  3. 课程
  4. /
  5. Shell 入门

Connected

道练习

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

为了了解命令的作用,过去人们常用 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 部分。

说明 1/2

undefined XP
  • 1

    阅读 tail 命令的手册页面,了解在与 -n 标志一起使用的数字前加上 + 号会有什么效果。(请按空格键向下翻页,或输入 q 退出。)

  • 2

    使用 tail 和标志 -n +7 显示 seasonal/spring.csv 中除前 6 行以外的所有内容。