Linux-第四天-获取帮助

8. 获取帮助 man & --help

8.1 man(manual pages)

  • 用途: 提供详细的命令、库函数、文件格式等的手册页。这是获取Linux命令或系统调用详细文档的最常见方式。
  • 用法: man [command],例如 man ls 会显示 ls 命令的完整手册页。
  • 特点: 手册页通常分为多个章节,如1-用户命令、2-系统调用、3-库函数等。
 man 1 普通用户在shell环境中可以执行的文件或命令
 man 2 系统内核可以调用的函数和工具
 man 3 一些常用的函数(function)和函数库(library), 大部分是C的函数库
 man 4 设备文件的说明, 通常在/dev/下的文件
 man 5 配置文件和某些文件的格式
 man 6 游戏娱乐
 man 7 标准协议。列如: Llunx文件系统、网络协议、ASCII code等说明
 man 8 系统管理员可用的管理命令
 man 9 跟内核有关的文件
 
 man *p 表示 POSI标准POSIX,全称为可移植性操作系统接口
 POSIX标准的基于UNIX操作系统的系统接口和环境来支持源代码级的可移植性
$# man 
[zy@localhost ~]$ 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
              with -l, print the author of each file

       -b, --escape
 Manual page ls(1) line 1 (press h for help or q to quit)

8.2 --help

  • 用途: 是大多数Linux命令内建的帮助选项,提供该命令的简短使用说明和可用选项列表。
  • 用法: 直接在命令后面加上 --help,例如 ls --help
  • 特点: 提供的信息相对简略,适合快速查看基本用法。
$# -- help
[zy@localhost ~]$ 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
SELinux options:

  --lcontext                 Display security context.   Enable -l. Lines
                             will probably be too wide for most displays.
  -Z, --context              Display security context so it fits on most
                             displays.  Displays only mode, user, group,
                             security context and file name.
  --scontext                 Display only security context and file name.
      --help     display this help and exit
      --version  output version information and exit

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'ls invocation'
[zy@localhost ~]$ 


9. 获取帮助强化

9.1 whereis

  • 用途: 用来查找给定命令的二进制文件、源代码文件和帮助手册页的位置。
  • 用法: whereis [command],比如 whereis ls 会显示 ls 命令的可执行文件、源代码和man手册的路径。
  • 特点: 可以快速定位程序文件位置,但不一定能找到所有相关文件。
$# 1. whereis    # 定位命令二进制源码位置, 该命令man手册位置
[zy@localhost Desktop]$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[zy@localhost Desktop]$ 

9.2 whatis

  • 用途: 显示命令或函数的简短描述,这些描述通常来源于man手册页的NAME部分。
  • 用法: whatis [command],例如 whatis ls 会输出 ls 命令的简短功能说明。
  • 特点: 适合快速了解命令的基本功能,而不必阅读完整的man手册
$# 2. whatis    # 查看man手册相关简要说明, 以及man类型
[zy@localhost Desktop]$ whatis ls
ls (1)               - list directory contents   
ls (1p)              - list directory contents
[zy@localhost Desktop]$ 

[zy@localhost Desktop]$ man 7 ip

IP(7)                              Linux Programmer's Manual                              IP(7)

NAME
       ip - Linux IPv4 protocol implementation

SYNOPSIS
       #include <sys/socket.h>
       #include <netinet/in.h>
       #include <netinet/ip.h> /* superset of previous */

       tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
       udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
       raw_socket = socket(AF_INET, SOCK_RAW, protocol);

DESCRIPTION
       Linux  implements  the  Internet Protocol, version 4, described in RFC 791 and RFC 1122.
       ip contains a level 2 multicasting implementation conforming to RFC 1112.  It also  con‐
       tains an IP router including a packet filter.

       The  programming  interface is BSD-sockets compatible.  For more information on sockets,
       see socket(7).

       An  IP  socket  is  created  by  calling  the  socket(2)  function  as   socket(AF_INET,
       socket_type,  protocol).   Valid  socket  types are SOCK_STREAM to open a tcp(7) socket,
 Manual page ip(7) line 1 (press h for help or q to quit)

9.3 which

  • 用途: 查找并显示指定命令的绝对路径,即在PATH环境变量中第一个找到的可执行文件的位置。
  • 用法: which [command],例如 which ls 会告诉你系统将执行哪个版本的 ls
  • 特点: 用于确定你将要执行的命令具体是哪一个,特别是在系统中有多个同名命令的情况下。
$# 3. which    # 查看命令二进制源代码位置, 可以查看当前命令alias别名
[zy@localhost Desktop]$ which ls
/usr/bin/ls
[zy@localhost Desktop]$ 


# 有很多命令后面都是省略了 --color  , 因为系统自带了
[zy@localhost ~]$ alias ls
alias ls='ls --color=auto'
[zy@localhost ~]$ 
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值