Linux获取命令帮助信息有哪些方式

在 Linux 系统中,获取命令帮助信息是一项非常重要的技能,它可以帮助用户快速了解命令的用法、参数和选项等内容。以下是几种常见的获取命令帮助信息的方式:

一、使用 man 命令

`man`(manual 的缩写)命令是 Linux 系统中最常用的获取命令帮助信息的方式之一。它可以显示命令的手册页,其中包含了命令的详细说明、用法示例、参数列表等信息。

例如,要获取`ls`命令的帮助信息,可以在终端中输入`man ls`命令。这将会打开`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.

-a, --all

do not hide entries starting with.

-A, --almost-all

do not list implied. and..

-b, --escape

print C-style escapes for nongraphic characters.

-B, --ignore-backups

do not list implied entries ending with ~.

-c, --time=ctime

with -lt: sort by, and show, ctime (time of last status change);

with -l: show ctime and sort by name; otherwise: sort by ctime, newest first.

-d, --directory

list directory entries instead of contents, and do not dereference symbolic links.

-f, --format=single-column

list one file per line.

-F, --classify

append indicator (one of */=>@|) to entries.

-g, --group

with -l: display the group names as well as the owner.

-h, --human-readable

with -l: print sizes in human readable format (e.g., 1K 234M 2G).

-i, --inode

print the index number of each file.

-l, --long

use a long listing format.

-L, --dereference

follow symbolic links only if they are listed.

-n, --numeric-uid-gid

print user and group IDs numerically.

-N, --literal

do not print ~ and.. for entries.

-o, --omit-dir-names

do not list names of directories.

-p, --indicator-style=slash

append / to directories.

-q, --hide-control-chars

print non-printing characters using ^ and M- notation.

-r, --reverse

reverse order while sorting.

-s, --size

print the allocated size of each file, in blocks.

-t, --time=atime

with -lt: sort by, and show, atime (time of last access);

with -l: show atime and sort by name; otherwise: sort by atime, newest first.

-T, --tabsize=N

assume tab stops at every N columns.

-u, --time=atime

with -lt: sort by, and show, atime (time of last access);

with -l: show atime and sort by name; otherwise: sort by atime, newest first.

-U, --unsorted

do not sort; list entries in directory order.

-v, --version-sort

sort alphabetically, but compare numeric suffixes first.

-w, --width=N

set output width to N columns.

-X, --sort=extension

sort by file extension.

-1, --one-file-system

list only files on one file system.

--color[=WHEN]

control whether color is used to distinguish file types.

WHEN can be 'never','always', or 'auto'.

--help

display this help and exit.

--version

output version information and exit.

EXAMPLES

ls

list the contents of the current directory.

ls -l

list the contents of the current directory in long format.

ls -a

list all files in the current directory, including hidden files.

ls -R

list the contents of all subdirectories recursively.

AUTHOR

GNU coreutils online help version 8.32

Written by David MacKenzie and others.

COPYRIGHT

Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

SEE ALSO

dircolors(1), vdir(1), vdircolors(1), find(1), glob(7), pathchk(1), printf(1), test(1), touch(1).

```

通过阅读`man`页面,用户可以了解`ls`命令的各种选项和用法,以及如何根据自己的需求进行定制。`man`页面通常非常详细,包含了命令的所有相关信息,是学习和使用 Linux 命令的重要参考资料。

二、使用 info 命令

`info`命令是另一种获取命令帮助信息的方式,它提供了更加结构化和交互式的帮助文档。`info`页面通常包含了命令的概述、详细说明、示例、相关命令等内容,并且可以通过链接和索引进行导航。

要获取`ls`命令的`info`页面,可以在终端中输入`info ls`命令。这将会打开`ls`命令的`info`页面,显示如下内容:

```

Node: ls invocation, Contents: [Top] [Index] [Search] [Next] [Previous] [Home] [Up]

ls invocation

(ls invocation)

Summary: List information about files.

Description:

The `ls' command lists information about the files in the current directory or the specified directory. It can display file names, sizes, timestamps, permissions, and other attributes.

Options:

- a: List all files, including hidden files.

- A: List all files except. and..

- b: Print non-printable characters in octal escape format.

- B: Do not list implied entries ending with ~.

- c: Sort by file status change time.

- d: List directories instead of their contents.

- f: List files in a single column.

- F: Append file type indicators to file names.

- g: Print group names instead of user names.

- h: Print human-readable file sizes.

- i: Print file inode numbers.

- l: Use a long listing format.

- L: Follow symbolic links.

- m: List files separated by commas.

- n: Print user and group names in numeric form.

- o: Do not print group information.

- p: Append / to directories.

- q: Print non-printable characters using quote characters.

- r: Reverse the order of sorting.

- s: Print file sizes in blocks.

- t: Sort by file modification time.

- u: Sort by file access time.

- v: Sort lexicographically, using version sort.

- x: Sort by file names within directories.

- 1: List one file per line.

Examples:

- ls: List files in the current directory.

- ls -l: List files in long format.

- ls -a: List all files in the current directory.

- ls -R: Recursively list files in subdirectories.

See Also:

dir(1), vdir(1), find(1), stat(1), file(1)

```

与`man`页面相比,`info`页面更加注重组织结构和交互性,用户可以通过点击链接和使用索引来快速找到自己需要的信息。`info`页面还提供了一些额外的功能,如搜索、注释和参考资料等,使得获取帮助信息更加方便和高效。

三、使用 --help 选项

许多 Linux 命令都支持`--help`选项,它可以显示命令的简短帮助信息,包括命令的用法、选项和参数等内容。

例如,要获取`ls`命令的`--help`信息,可以在终端中输入`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.

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

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

-b, --escape print C-style escapes for nongraphic characters

-B, --ignore-backups do not list implied entries ending with ~

-c, --time=ctime with -lt: sort by, and show, ctime (time of last status change);

with -l: show ctime and sort by name; otherwise: sort by ctime,

newest first

-d, --directory list directory entries instead of contents, and do not

dereference symbolic links

-f, --format=single-column

list one file per line

-F, --classify append indicator (one of */=>@|) to entries

-g, --group with -l: display the group names as well as the owner

-h, --human-readable with -l: print sizes in human readable format (e.g., 1K 234M 2G)

-i, --inode print the index number of each file

-l, --long use a long listing format

-L, --dereference follow symbolic links only if they are listed

-n, --numeric-uid-gid

print user and group IDs numerically

-N, --literal do not print ~ and.. for entries

-o, --omit-dir-names do not list names of directories

-p, --indicator-style=slash

append / to directories

-q, --hide-control-chars

print non-printing characters using ^ and M- notation

-r, --reverse reverse order while sorting

-s, --size print the allocated size of each file, in blocks

-t, --time=atime with -lt: sort by, and show, atime (time of last access);

with -l: show atime and sort by name; otherwise: sort by atime,

newest first

-T, --tabsize=N assume tab stops at every N columns

-u, --time=atime with -lt: sort by, and show, atime (time of last access);

with -l: show atime and sort by name; otherwise: sort by atime,

newest first

-U, --unsorted do not sort; list entries in directory order

-v, --version-sort sort alphabetically, but compare numeric suffixes first

-w, --width=N set output width to N columns

-X, --sort=extension sort by file extension

-1, --one-file-system list only files on one file system

--color[=WHEN] control whether color is used to distinguish file types

WHEN can be 'never', 'always', or 'auto'

--help display this help and exit

--version output version information and exit

GNU coreutils online help version 8.32

Written by David MacKenzie and others.

Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

```

`--help`选项提供了一个简洁明了的命令帮助信息,适合快速了解命令的基本用法和选项。对于一些简单的命令,`--help`选项通常就足够了。

四、使用在线文档和社区资源

除了上述本地的命令帮助方式,还可以通过在线文档和社区资源获取更详细和最新的命令帮助信息。

Linux 官方网站提供了丰富的文档和资源,包括命令手册、教程、FAQ 等。可以通过访问[https://www.gnu.org/software/coreutils/manual/coreutils.html](https://www.gnu.org/software/coreutils/manual/coreutils.html)来获取`coreutils`命令集的详细文档,其中包含了许多常用命令的帮助信息。

Linux 社区也是获取命令帮助的重要来源。可以通过在搜索引擎中输入相关命令加上“Linux 教程”、“Linux 命令帮助”等关键词,找到大量的在线教程和社区讨论。这些资源通常由经验丰富的用户和开发者提供,能够提供更深入和实用的帮助。

例如,在[https://www.linux.com/tutorials/command-line/](https://www.linux.com/tutorials/command-line/)网站上,有许多关于 Linux 命令的教程和指南,可以帮助用户更好地理解和使用各种命令。

在 Linux 系统中,获取命令帮助信息有多种方式可供选择。用户可以根据自己的需求和习惯,灵活使用`man`命令、`info`命令、`--help`选项以及在线文档和社区资源,以快速获取所需的命令帮助信息,提高工作效率。

网友留言(0 条)

发表评论

验证码