2.7 查看命令帮助信息

一个命令他的格式是什么?有几个选项?我们去哪里去查呢?

我常用两种方法:

  1. --help 选项查看。格式: 命令 --help
  2. 使用 man 命令查看此命令的手册。格式 man 命令

使用 --help 选项查看 ls 命令都有哪些用法?

weimingze@mzstudio:~$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  ...... 以下省略

使用 man 命令查看 ls 命令都有哪些用法?

weimingze@mzstudio:~$ man ls
LS(1)                                                                             User Commands                                                                            LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

       Mandatory arguments to long options are mandatory for short options too.

       -a, --all
              do not ignore entries starting with .

       -A, --almost-all
              do not list implied . and ..

       --author
    ....... 以下省略

使用上下方向键可以翻页,按 q 键可以退出帮助手册。

命令自动补全

当我们使用终端来输入命令的时候,如果命令或参数过长,我们可以先输入几个字符,然后按 <tab> 键(Q左侧的按键)去补全剩余的字符。这样可以大大提高我们输入的效率,避免出错。

比如,我们要输入 touch 命令,当我们输入 tou 时按下 <tab> 键,则会补全剩余字符。

weimingze@mzstudio:~$ tou

关于文件操作相关命令我们就先讲到这里了。

练习: