Linux命令详解用法_man < COMMAND>

本文全面解析了man命令的使用方法,包括基本用法、章节说明、帮助命令与搜索技巧,以及如何利用man命令获取Linux系统中各种命令的手册页信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

▼man COMMAND

man 的基本用法

[root@CentOS7 ~]$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 ..
...

▼man帮助手册说明:

  1. NAME名称及简要说明
  2. SYNOPSIS 用法格式说明
    [ ] 可选内容
    < > 必选内容
    a|b 二选一
    { } 分组
    ... 同一内容可出现多次
  3. DESCRIPTION详细说明
  4. OPTIONS选项说明
  5. EXAMPLES 示例
  6. FILES 相关文件
  7. AUTHOR作者
  8. COPYRIGHT 版本信息
  9. REPORTING BUGS bug信息
  10. SEE ALSO其它帮助参考

▷man的章节说明

  • man手册有章节之分.
    章节查看:命令whatis COMMAND的标准输出,命令后括号就是章节
[root@CentOS7 ~]$whatis passwd
passwd (1)           - update user's authentication tokens
sslpasswd (1ssl)     - compute password hashes
passwd (5)           - password file
  • 各章节的意义
章节序号意义
1Executable programs or shell commands \\可执行程序或shell命令
2System calls (functions provided by the kernel) \\系统调用
3Library calls (functions within program libraries) \\库函数
4Special files (usually found in /dev) \\特殊文件(通常为设备)
5File formats \\文件格式
6Games \\游戏
7Miscellaneous \\杂项
8System administration commands \\系统管理员命令
9Kernel routines\\内核例程

▷man帮助命令

space or ^v or ^f or ^F : 向文件尾翻屏

b or ^b : 向文件首部翻屏

d or ^d : 向文件尾部翻半屏

u or ^u : 向文件首部翻半屏

RETURN or ^N or e or ^E or j or ^J : 向文件尾部翻一行

y or ^Y or ^P or k or ^K :向文件首部翻一行

q 退出

# :跳转至第#行

1G : 回到文件首部

G :翻至文件尾部

▷man帮助搜索

  • /KEYWORD
    • 以KEYWORD指定的字符串为关键字,从当前位置向文件尾部搜索;不区 分字符大小写;
      n: 下一个 , N:上一个
  • ?KEYWORD
    • 以KEYWORD指定的字符串为关键字,从当前位置向文件首部搜索;不区 分字符大小写;
      n: 上一个 , N:下一个

▼man的其它用法

1. man [章节] keyword 查看man手册页

[root@CentOS7 ~]$whatis passwd
passwd (1)           - update user’s authentication tokens
sslpasswd (1ssl)     - compute password hashes
passwd (5)           - password file
[root@CentOS7 ~]$man 5 passwd

PASSWD(5)                     Linux Programmer’s Manual                    PASSWD(5)

NAME
       passwd - password file

DESCRIPTION
       The  /etc/passwd  file  is a text file that describes user login accounts for
       the system.  It should have read permission allowed for all users (many util‐
       ities, like ls(1) use it to map user IDs to usernames), but write access only
       for the superuser.

       In the good old days there was no great problem with this general  read  per‐
       mission.   Everybody could read the encrypted passwords, but the hardware was
       too slow to crack a well-chosen password, and moreover the  basic  assumption
       used  to  be  that  of a friendly user-community.  These days many people run
       some version of the shadow password suite, where /etc/passwd has an 'x' char‐
       acter  in the password field, and the encrypted passwords are in /etc/shadow,
       which is readable by the superuser only.

       If the encrypted password, whether in /etc/passwd or in  /etc/shadow,  is  an
       empty string, login is allowed without even asking for a password.  Note that
       this functionality may be intentionally disabled in applications, or  config‐
       urable (for example using the "nullok" or "nonull" arguments to pam_unix.so).
...

2. man –a keyword列出所有帮助

查看完第一个ls(1)后提示
--Man-- next: ls(1p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
ENTER继续查看ls(1p)

[root@CentOS7 ~]$whatis ls
ls (1)               - list directory contents
ls (1p)              - list directory contents
[root@CentOS7 ~]$man -a 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.
...

[root@CentOS7 ~]$man -a ls
--Man-- next: ls(1p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]



LS(1P)                        POSIX Programmer‘s Manual                       LS(1P)

PROLOG
       This  manual page is part of the POSIX Programmer's Manual.  The Linux imple‐
       mentation of this interface may differ (consult the corresponding Linux  man‐
       ual  page  for details of Linux behavior), or the interface may not be imple‐
       mented on Linux.

NAME
       ls - list directory contents

SYNOPSIS
       ls [-CFRacdilqrtu1][-H | -L ][-fgmnopsx][file...]

3. man –f keyword显示手册中的简短描述

相当于 whatis

[root@CentOS7 ~]$whatis ls
ls (1)               - list directory contents
ls (1p)              - list directory contents
[root@CentOS7 ~]$man -f ls
ls (1)               - list directory contents
ls (1p)              - list directory contents

4. man -k keyword搜索man手册

相当于apropos
搜索的是man手册的'NAME'字段

[root@CentOS7 ~]$man -k 'list directory'
dir (1)              - list directory contents
ls (1)               - list directory contents
ls (1p)              - list directory contents
vdir (1)             - list directory contents

[root@CentOS7 ~]$apropos 'list directory'
dir (1)              - list directory contents
ls (1)               - list directory contents
ls (1p)              - list directory contents
vdir (1)             - list directory contents

5. man –w [章节] keyword打印man帮助文件的路径

[root@CentOS7 ~]$man -w 1 ls
/usr/share/man/man1/ls.1.gz	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十三y

你的鼓励就是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值