Linux 错误信息的查看(摘自鸟哥的私房菜一书)

个人认为学会看错误信息是身份重要的

错误信息的查看

[root@izuf6bitohktz5v96aq6dtz ~]# Date
-bash: Date: command not found

command not found:命令不存在,可能原因如下:

  1. 这个命名不存在,因为该软件没有安装的缘故,解决方法就是安装该软件
  2. 这个命令所在的目录目前额用户并没有将它加入命令查找路径中
  3. 自己输入错误

Linux系统的在线求助 man page 与 info page(我记得还有一个 --help 命令)

1.help 命令
[root@izuf6bitohktz5v96aq6dtz ~]# date --help
Usage: date [OPTION]... [+FORMAT]		#基本语法
  or:  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=FILE      display the last modification time of FILE
  -R, --rfc-2822            output date and time in RFC 2822 format.
                            Example: Mon, 07 Aug 2006 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     display this help and exit		#显示次帮助并离开
      --version  output version information and exit	#显示版本信息并离开
#下面是重要的格式主要项目
FORMAT controls the output.  Interpreted sequences are:

  %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  ...略
  #下面是几个重要的范例
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'

man page

man 是 manual(操作说明)的简写:


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.

       -r, --reference=FILE
              display the last modification time of FILE

       -R, --rfc-2822
              output date and time in RFC 2822 format.  Example: Mon, 07 Aug 2006 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 display this help and exit

       --version
              output version information and exit
		#下面是格式化输出的详细信息
       FORMAT controls the output.  Interpreted sequences are:

       %%     a literal %

       %a     locale's abbreviated weekday name (e.g., Sun)

       %A     locale's full weekday name (e.g., Sunday)
		...省略
ENVIRONMENT	#与整个命令相关的环境参数有如下说明
       TZ     Specifies the timezone, unless overridden by command line parameters.  If neither is  speci‐
              fied, the setting from /etc/localtime is used.

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

DATE STRING	#上面提到的 --date 格式声明
       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 com‐
       plex than is easily documented here but is fully described in the info documentation.

AUTHOR	#这个命令的作者
       Written by David MacKenzie.

COPYRIGHT	#受到著作权法的保护,用的就是 GPL
       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	#这个重要,你还可以从哪里查到与date 相关的说明文件
       The full documentation for date is maintained as a Texinfo manual.  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.

在上面中:出现了DATE(1),这个1 是什么意思(把他再弄一份吧)


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.

代号代表内容
1用户在 shell 环境中可以操作的命令或可执行文件
2系统内核可调用的函数与工具等
3一些常用的函数(function)与函数库(library),大部分为C的函数库(libc)
4设备文件的说明,通常在 /dev 下的文件
5配置文件或是某些文件的格式
6游戏(games)
7惯例与协议等,例如:Linux 文件系统\网络协议、ASCII代码等的说明
8系统管理员可用的管理命令
9跟内核有关的文件

基本上man page大致分成下面这几个部分:

代号内容说明
NAME简短的命令、数据名称说明
SYNOPSIS简短的命令语法(syntax)简介
DESCRIPTION比较完整的说明,这部分最好仔细看
OPTIONS针对 SYNOPSIS部分中,有列举所有可能的选项说明
COMMANDS当这个程序(软件) 在执行的时候,可以在此程序(软件)中执行的命令
FILES这个程序或数据所使用或参数或链接到的某些文件
SEE ALSO可以参考跟这个命令或数据有相关的其它说明
EXAMPLE一些可以参考的范例

查看某个数据的方法(萝卜青菜各有所爱,自己觉得行就好),如下:

  1. 先查看 Name 的部分,约略看一下这个数据的意思
  2. 再详看一下 DESCRIPTION,这个部分会提到很多的数据与使用的时机,从这个地方可以学到很多小细节
  3. 而如果这个命令其实很熟悉了,那么可以查阅 OPTIONS的部分了。可以知道每个选项的意义,这样就可以执行比较详细的命令内容
  4. 最后,再看一下,跟这个数据有关的还有哪些东西可以使用,如:SEE ALSO就告诉我们还可以利用 【info coreutils ‘date invocation’】来进一步查看帮助
  5. 某些说明内容还会列举有关的文件来提供我们参考,这些都是很有帮助的

帮助查看的按键:

按键进行工作
空格键向下翻一页
[Page Down]向下翻一页
[Page Up]向上翻一页
[Home]去到第一页
End去到最后一页
/string向【下】查找string 这个字符串,如果要查找 vbird的话,就输入 /vbird
?string向【上】查找string 这个字符串
n,N利用 / 或 ?来查找字符串时,可以利用 n 来继续查找(不论是 / 或 ?),可以利用 N 来进行【反向】查找。举例来说,我以/vbird 查找 vbird 字符串,那么可以按下 n 继续往下查询,用 N往上查询。若以 ?vbird 向上查询 vbird 字符串,那么我可以用 n 继续向上查询,用 N 反向查询
q结束这次的man page

注意:上面的按键时在 man page 的界面才能使用

[root@izuf6bitohktz5v96aq6dtz ~]# whatis man    #等效于man -f [命令或是文件]
man (1)              - an interface to the on-line reference manuals
man (7)              - macros to format man pages
man (1p)             - display system documentation

[root@izuf6bitohktz5v96aq6dtz ~]# apropos man #等效于 man -k [命令或是文件]
. (1)                - bash built-in commands, see bash(1)
: (1)                - bash built-in commands, see bash(1)
[ (1)                - bash built-in commands, see bash(1)
accessdb (8)         - dumps the content of a man-db database in a human readable format
add_key (2)          - add a key to the kernel's key management facility

3.info page

在所有的UNIX-like 系统中,都可以利用man来查询命令或是相关的文件。基本上 info 与 man 的用途都差不多,都是用来查询命令的用法或是文件的格式。但与 man 命令不同的是,info page 则是将文件数据拆成一个一个段落,每个段落用自己的页面来编写,并且在各个页面中还有类似网页的超级链接来跳转到各不同的页面中,每个独立的页面页被称为一个节点,所以,我们可以将info page 想成是命令行模式的网页数据。
不过要查询的目标数据的说明文件要以 info 的格式来写成才能使用 info的特殊功能,而这个支持 info 命令的文件默认是放置在 /usr/share/info/ 这个目录中,如:

[root@izuf6bitohktz5v96aq6dtz ~]# 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.
.....省略

第一行显示了很多的信息:

  1. File:代表这个 info page 的数据来自 info.info 文件提供
  2. Node:代表目前的这个页面是属于 Top 节点,意思是 info.info 内含有很多信息,而 Top 仅是 info.info 文件内的一个节点内容而已
  3. Next:下一个节点的名称为 Getting Started, 可以通过按 【N】到下一个节点去、
  4. Up:回到上一层的节点总览画面,可以通过按【U】 回到上一层
  5. Pre: 前一个节点,但由于 Top 是 info.info 的第一个节点所以上面没有前一个节点的信息

只要不知道怎么使用info , 直接按下 h,系统就能够提供一些基本的按键功能介绍:

File: info.info,  Node: Top,  Next: Getting Started,  Up: (dir)

Info: An Introduction
*********************
	中间省略........
   To read about advanced Info commands, type 'n' twice.  This brings
you to 'Advanced Info Commands', skipping over the 'Getting Started'
--zz-Info: (info.info.gz)Top, 52 lines --Top----------------------------------------------------------------------------------------------
Basic Info command keys

x           Close this help window.
q           Quit Info altogether.
H           Invoke the Info tutorial.

Up          Move up one line.
Down        Move down one line.
DEL         Scroll backward one screenful.
SPC         Scroll forward one screenful.
Home        Go to the beginning of this node.
End         Go to the end of this node.

TAB         Skip to the next hypertext link.
RET         Follow the hypertext link under the cursor.
l           Go back to the last node seen in this window.

[           Go to the previous node in the document.
]           Go to the next node in the document.
-----Info: *Info Help*, 347 lines --Top--------------------------------------------------------------------------------------------------

操作如下:
在这里插入图片描述

按键进行工作
空格键向下翻页
[Page Down]向下翻页
Page Up向上翻页
[Tab]在节点之间移动,有节点的地方,通常会显示*
[Enter]当光标在节点上面时,按下 Enter 可以进入该节点
b移动光标到该 info 界面当中的第一处
e移动光标到该 info 界面当中的最后一个节点处
n前往下一个节点
p前往上一个节点
u向上移动一层
s(/)在 info page当中进行查找
h,?显示帮助选项
q结束这次的 info page
其它有用文件

一般而言,命令或软件制作者,都会将自己的命令或是软件的说明制作成联机帮助文件。但是,并毕竟不是每个东西都需要制成联机帮助文件的,还有相当多的说明需要额外的文件。这是怎么做就很重要了。还有某些软件不只是告诉你如何做,还会有一些原理会说明。那么,这些文件摆放在哪里呢? 就摆放在 /usr/share/doc 这个目录。只要你到这个目录,就会发现很多的说明文件,根本就不需要到网上找数据

总结:

  1. 在命令行模式中,如果你知道莫格命令,但却忘记了相关选项与参数,请先使用 【–help】的功能来查询相关信息
  2. 当有任何不到的命令或文件格式这种玩意儿,但你想要了解它,请赶快使用 man 或 info 来查询
  3. 如果你想要假设一些其它服务,或想要利用一整组软件来完成某项功能时,请赶快到 /usr/share/doc 下查一查又没有该服务的说明文件
  4. 最后,因为 linux 是外国人发明的,所以中文文档确实比较少
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值