欢迎使用CSDN-markdown编辑器

Linux Command:命令帮助

本人原文地址:http://www.deleiguo.com/archives/279
转载请附带原文地址
指导环境:CentOS7

Linux命令数量

在Linux下,如果不记得命令的全称,但知道前面几个字母,可以通过tab自动补全,或按下两次tab列出相符的多个可选项;

[root@delei-server ~]# ls
ls        lscgroup  lsinitrd  lsmcli    lsof      lssubsys
lsattr    lscpu     lslocks   lsmd      lspci     lsusb
lsblk     lsdiff    lslogins  lsmod     lsscsi    lsusb.py

而当匹配的数量过多,会先先统计有多少数量,询问是否显示

[root@delei-server ~]# c
Display all 199 possibilities? (y or n)

那么,我们可以在不输入任何字的情况下,直接按下两次tab键,则可以统计下当前用户下可用的命令有多少个.

但是经过实际尝试,在CenOS7下,该方法无效,Mac下有效

delei@DeleitekiMBP:~$
Display all 1473 possibilities? (y or n)

每个人的操作系统所用的命令数都是不一样的。
不同的linux版本,用户安装的软件命令,用户设置的环境变量等都是不一样的。

虽然经常常用的命令数量不多,但是在有些情况下,很多命令的详细参数和选项用法不一定都能记得住。而若在无网络,无参考手册情况下,更会遇到不知道如何使用命令的情况。Linux上开发的软件大多数是自由性软件,而这些软件开发者一般都会有相应的命令使用方法。
在上述情况下,其实Linux已提供了几种方式能够提供帮助。

whatis

该命令获得索引的简短信息,如果有多个匹配(不同版本,多个同样的软件等)则会列出多个

[root@delei-server ~]# whatis cd
cd (1)               - bash built-in commands, see bash(1)
cd (1p)              - change the working directory
[root@delei-server ~]# whatis wget
wget (1)             - The non-interactive network downloader.

但不是所有命令在所有的Linux上均可使用

[root@delei-server ~]# whatis ll
ll:没有 appropriate。

help、-help

–help该命令显示使用摘要和参数列表,可以查看大多数命令的用法

[root@delei-server ~]# date --help
用法:date [选项]... [+格式]
 或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.

Mandatory arguments to long options are mandatory for short options too.
  -d, --date=STRING         display time described by STRING, not 'now'
  -f, --file=DATEFILE       like --date once for each line of DATEFILE
  -I[TIMESPEC], --iso-8601[=TIMESPEC]  output date/time in ISO 8601 format.
                            TIMESPEC='date' for date only (the default),
                            'hours', 'minutes', 'seconds', or 'ns' for date
                            and time to the indicated precision.
  -r, --reference=文件        显示文件指定文件的最后修改时间
  -R, --rfc-2822        以RFC 2822格式输出日期和时间
                例如:200687日,星期一 12:34:56 -0600
      --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.
                            TIMESPEC='date', 'seconds', or 'ns' for
                            date and time to the indicated precision.
                            Date and time components are separated by
                            a single space: 2006-08-07 12:34:56-06:00
  -s, --set=STRING          set time described by STRING
  -u, --utc, --universal    print or set Coordinated Universal Time (UTC)
      --help        显示此帮助信息并退出
      --version     显示版本信息并退出

给定的格式FORMAT 控制着输出,解释序列如下:

  %%    一个文字的 %
  %a    当前locale 的星期名缩写(例如: 日,代表星期日)
  %A    当前locale 的星期名全称 (如:星期日)
  %b    当前locale 的月名缩写 (如:一,代表一月)
  %B    当前locale 的月名全称 (如:一月)
  ...

默认情况下,日期的数字区域以0 填充。
The following optional flags may follow '%':

  -  (hyphen) do not pad the field
  _  (underscore) pad with spaces
  0  (zero) pad with zeros
  ^  use upper case if possible
  #  use opposite case if possible

在任何标记之后还允许一个可选的域宽度指定,它是一个十进制数字。
作为一个可选的修饰声明,它可以是E,在可能的情况下使用本地环境关联的
表示方式;或者是O,在可能的情况下使用本地环境关联的数字符号。

Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date
  $ date --date='@2147483647'

Show the time on the west coast of the US (use tzselect(1) to find TZ)
  $ TZ='America/Los_Angeles' date

Show the local time for 9AM next Friday on the west coast of the US
  $ date --date='TZ="America/Los_Angeles" 09:00 next Fri'

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告date 的翻译错误
要获取完整文档,请运行:info coreutils 'date invocation'

–help只能对外部命令使用,对内部命令无效当我们要求内部命令的帮助时使用help+命令

[root@delei-server bin]# help pwd
pwd: pwd [-LP]
    打印当前工作目录的名字。

    选项:
      -L    打印 $PWD 变量的值,如果它命名了当前的
        工作目录
      -P    打印当前的物理路径,不带有任何的符号链接

    默认情况下,`pwd' 的行为和带 `-L' 选项一致

    退出状态:
    除非使用了无效选项或者当前目录不可读,否则
    返回状态为0

man

man是manual的简写,命令使用手册/说明
同样是pwd,man提供的内容较多(内容过长,部分已省略…)

[root@delei-server bin]# man date
DATE(1)                       User Commands                      DATE(1)

NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
       Display  the  current time in the given FORMAT, or set the system
       date.

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

       -d, --date=STRING
              display time described by STRING, not 'now'

       -f, --file=DATEFILE
              like --date once for each line of DATEFILE

       -I[TIMESPEC], --iso-8601[=TIMESPEC]
              output  date/time in ISO 8601 format.  TIMESPEC='date' for
              date only (the default), 'hours', 'minutes', 'seconds', or
              'ns' for date and time to the indicated precision.

       ...
       #      use opposite case if possible

       After any flags comes an optional field width, as a decimal  num‐
       ber;  then  an  optional  modifier,  which is either E to use the
       locale's alternate representations if available, or O to use  the
       locale's alternate numeric symbols if available.

ENVIRONMENT
       TZ     Specifies  the timezone, unless overridden by command line
              parameters.  If neither is  specified,  the  setting  from
              /etc/localtime is used.

EXAMPLES
       Convert seconds since the epoch (1970-01-01 UTC) to a date

              $ date --date='@2147483647'

       Show  the  time  on  the west coast of the US (use tzselect(1) to
       find TZ)

              $ TZ='America/Los_Angeles' date
    ...

DATE STRING
       The  --date=STRING  is  a  mostly free format human readable date
       string such as "Sun, 29 Feb 2004 16:21:42 -0800"  or  "2004-02-29
       16:21:42"  or  even  "next  Thursday".  A date string may contain
       items indicating calendar date, time of day, time  zone,  day  of
       week, relative time, relative date, and numbers.  An empty string
       indicates the beginning of the day.  The date  string  format  is
       more  complex  than  is  easily  documented  here  but  is  fully
       described in the info documentation.

AUTHOR
       Written by David MacKenzie.

COPYRIGHT
       Copyright © 2013 Free Software Foundation, Inc.  License  GPLv3+:
       GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
       This  is  free  software: you are free to change and redistribute
       it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       The full documentation for date is maintained as a  Texinfo  man‐
       ual.   If  the  info  and date programs are properly installed at
       your site, the command

              info coreutils 'date invocation'

       should give you access to the complete manual.

GNU coreutils 8.22            February 2016                      DATE(1)
 Manual page date(1) line 159/222 (END) (press h for help or q to quit)

当内容较多时,使用page up和page down上下翻页,空格也可向下翻页;
按q退出

在man的帮助手册中,将帮助文档分为了9个类别,对于有的关键字可能存在多个类别中, 我们就需要指定特定的类别来查看;(一般我们查询bash命令,归类在1类中);

man页面所属的分类标识(常用的是1、3、5、8)
  1. 用户可以操作的命令或者是可执行文件
  2. 系统核心可调用的函数与工具等
  3. 一些常用的函数与数据库
  4. 设备文件的说明
  5. 设置文件或者某些文件的格式
  6. 游戏
  7. 惯例与协议等。例如Linux标准文件系统、网络协议、ASCⅡ,码等说明内容
  8. 系统管理员可用的管理条令
  9. 与内核有关的文件
man page的常见部分
名称内容说明
NAME简短的指令、资料名称说明
SYNOPSIS简短的指令下达语法简介
DESCRIPTION较为完整的说明
OPTIONS针对SYNOPSI部分,有列举的所有可用的选项说明
COMMANDS当该命令在运行的时候,可以下达的命令
FILES使用或链接到的某些档案/文件
SEE ALSO可以参考的,跟该命令或资料有相关的其他说明
EXAMPLE可以参考的范例
AUTHORS作者
COPYRIGHT版权说明

这是常见的内容,实际上还有其他部分
在某些命令中这些内容不全都有

man常用命令参数
  • man -a:
    搜索并打开所有man中同名帮助,例如 man passwd ,你首先会进入一个PASSWD(1) section用户命令类的帮助手册,你再按q键退出当前正在显示的帮助手册,就会进入PASSWD(5) section文件格式类的帮助手册。

  • man -aw:
    显示所有手册文件的路径。

[root@delei-server bin]# man -aw passwd
/usr/share/man/man1/passwd.1.gz
/usr/share/man/man1/sslpasswd.1ssl.gz
/usr/share/man/man5/passwd.5.gz
  • man -M:
    指定手册文件的搜索路径,有的时候我们自己安装的软件是带有自己的帮助文件的,通常不在我们的MANPATH里面,那么我们就可以手动指定man搜索的文件路径。如 man -M /home/mysql/man mysql显示的就是你安装的mysql的帮助,而不是系统默认的旧版mysql的帮助。

  • man -k:
    根据关键字搜索联机帮助,是一种模糊搜索。例如要查找”passwd”相关的信息,使用man -k passwd会找到很多和passwd相关的帮助页。如:我忘记了iptables命令就只能记住ipta则可以使用man -k ipta ,系统会把包括ipta的命令显示在屏幕上。

[root@delei-server bin]# man -k passwd
chpasswd (8)         - 批量更新密码
gpasswd (1)          - 管理员 /etc/group 和 /etc/gshadow
fgetpwent_r (3)      - get passwd file entry reentrantly
getpwent_r (3)       - get passwd file entry reentrantly
grub2-mkpasswd-pbkdf2 (1) - Generate a PBKDF2 password hash.
htpasswd (1)         - Manage user files for basic authentication
kpasswd (1)          - change a user's Kerberos password
ldappasswd (1)       - change the password of an LDAP entry
lpasswd (1)          - Change group or user password
lppasswd (1)         - add, change, or delete digest passwords.
pam_localuser (8)    - require users to be listed in /etc/passwd
passwd (1)           - update user's authentication tokens
sslpasswd (1ssl)     - compute password hashes
passwd (5)           - password file
passwd2des (3)       - RFS password encryption
pwhistory_helper (8) - Helper binary that transfers password hashes fro...
saslpasswd2 (8)      - set a user's sasl password
smbpasswd (5)        - The Samba encrypted password file
smbpasswd (8)        - change a user's SMB password
vncpasswd (1)        - change the VNC password
  • man -f:
    关键字精确搜索,与-k不同,它只搜索与关键字完全匹配的帮助页。
[root@delei-server bin]# man -f passwd
sslpasswd (1ssl)     - compute password hashes
passwd (1)           - update user's authentication tokens
passwd (5)           - password file

info

info与man类似,也是一种帮助说明,指令的文件预设放在/usr/share/info/目录中。
与man不同的是,info不是都在一个页面显示,而是将文件资料拆成了多个段落,每个段落有自己的页面,并且在各个页面还有类似链接的方式可以跳转,每个页面被称为一个node.

[root@delei-server bin]# info info
File: info.info,  Node: Top,  Next: Getting Started,  Up: (dir)

Info: An Introduction
*********************

The GNU Project distributes most of its on-line manuals in the "Info
format", which you read using an "Info reader".  You are probably using
an Info reader to read this now.

   ...

* Menu:

* Getting Started::             Getting started using an Info reader.
* Advanced::                    Advanced Info commands.
* Expert Info::                 Info commands for experts.
* Index::                       An index of topics, commands, and variabl\
es.

第一行:
* File:表示该info的内容是由info.info提供
* Node:代表当前的这个页面是top
* Next:下一个页面
* Up:上一个页面

将光标移动到该页面最下面”Menu”的列表部分,在每一个种,按下回车即可进入到相应的Node(类似于网页的链接跳转)

File: info.info,  Node: Advanced,  Next: Expert Info,  Prev: Getting Star\
ted,  Up: Top

2 Advanced Info Commands
************************

This chapter describes various advanced Info commands.  (If you are
using a stand-alone Info reader, there are additional commands specific
to it, which are documented in several chapters of *note GNU Info:
(info-stnd)Top.)

   ...

* Menu:

* Search Text::          How to search Info documents.
* Search Index::         How to search the indices for specific subjects.
* Go to node::           How to go to a node by name.
* Choose menu subtopic:: How to choose a menu subtopic by its number.
* Create Info buffer::   How to create a new Info buffer in Emacs.
* Emacs Info Variables:: Variables modifying the behavior of Emacs Info.

依照Menu可以进行node间的跳转,比起man来说,阅读更加方便

参考文献

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值