目錄
1、Linux 的命令行模式
2、help 命令
3、man 命令
4、man 命令輸出文檔漢化
? ? ? ? 注:本文檔使用 Linux 版本為 CentOS 7.9
[swadian@localhost ~]$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
1、Linux 的命令行模式
????????一般情況下,我們使用 Linux,都是通過特定的程序跟 Linux 系統(tǒng)進(jìn)行溝通的,這個特定的程序就被稱為殼程序(Shell),Linux 的殼程序就是 BASH。
????????Linux 的命令行格式:
[swadian@localhost ~]$ command [-options] parameterl parameter2
命令 選項(xiàng) 參數(shù)1 參數(shù)2
????????上述命令詳細(xì)說明如下:
- 一行命令中第一個輸入的部分絕對是命令 (command ) 或可執(zhí)行文件 (例如 shell 腳本),command 為命令的名稱,例如變換工作目錄的命令為 cd 等。
- 中擴(kuò)號 [] 并不存在于實(shí)際的命令中,表示是可選的,而加入選項(xiàng)設(shè)置時,通常選項(xiàng)前會帶 - 號,例如 -h;有時候會使用選項(xiàng)的完整全名,則選項(xiàng)前帶有 -- 符號,例如 --help。
- parameter1 parameter2 為依附在選項(xiàng)后面的參數(shù),或是 command 的參數(shù)。
????????命令、選項(xiàng)、參數(shù)等這幾個東西中間以空格來區(qū)分,不論空幾格 shell 都視為一格,所以空格是很重要的特殊字符。
????????Linux 系統(tǒng)中有非常多的命令,而且不同版本的 Linux 命令也稍有不同,那,這么多的命令都需要我們?nèi)ニ烙浻脖硢幔?/em>
????????答案是:當(dāng)然不需要,我們只需要知道知道怎樣使用聯(lián)機(jī)文檔就可以了。
2、help 命令
? ? ? ? 首先,如果你知道一個命令,但是不清楚它的具體用法,你只要使用 [--help] 這個選項(xiàng),就能夠?qū)υ撁畹挠梅ㄓ幸粋€大致的理解,例如,下邊是 date 這個命令的基本用法與選項(xiàng)參數(shù)的介紹:
[swadian@localhost ~]$ 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)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 20)
%d day of month (e.g., 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric time zone (e.g., -0400)
%:z +hh:mm numeric time zone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
By default, date pads numeric fields with zeroes.
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
After any flags comes an optional field width, as a decimal number;
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.
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/>
For complete documentation, run: info coreutils 'date invocation'
????????在上邊的顯示文檔中,首先一開始是執(zhí)行命令的語法 (Usage):
Usage: date [OPTION]... [+FORMAT] #1、基本語法
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] #2、設(shè)置事件的語法
Display the current time in the given FORMAT, or set the system date.
#顯示指定格式的當(dāng)前時間,或者設(shè)置系統(tǒng)日期。
? ? ? ? Usage 中說明,這個 date 有兩種基本語法,一種是直接執(zhí)行并且取得日期返回值,且可以 +FORAMAT 的方式來顯示。至于另一種方式,則是加上 MMDDhhmmCCYY 的方式來設(shè)置日期時間,它的格式是 [月月日日時時分分公元年] 的格式。
????????再往下看,會列舉一些主要的選項(xiàng),例如 -d,-f,-r 的意義, +FORMAT 的用法等:
# 主要的選項(xiàng)說明
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
#省略.....
#下面則是重要的格式 (FORMAT)的主要項(xiàng)目
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)
#省略.....
????????然后再接下來,就是該命令的幾個使用示例:
# 使用示例
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
#省略.....
????????基本上如果是命令,那么通過這個簡單的 [--help] 就可以很快速地取得你所需要的選項(xiàng)、參數(shù)的說明。這里說明一下,盡管我們不需要硬背命令參數(shù),但是常用的命令還是得記憶一下,而選項(xiàng)就通過 [--help] 來快速查詢即可。
????????但是,如果你要使用的是從來沒有用過得命令,或是你要查詢的根本就不是命令,而是文件的格式時,那又該怎么辦呢?那么,你就需要使用 man page 命令了。
3、man 命令
????????這個 man 是 manual (操作說明) 的簡寫。該命令提供比 help 更加詳細(xì)的文檔說明。以下是執(zhí)行:[man date] 的示例:
[swadian@localhost ~]$ man date
DATE(1) User Commands DATE(1)
NAME #簡短的命令,數(shù)據(jù)名稱說明
date - print or set the system date and time
SYNOPSIS #簡短的命令語法簡介
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION #較為完整的說明(重點(diǎn))
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)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 20)
%d day of month (e.g., 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric time zone (e.g., -0400)
%:z +hh:mm numeric time zone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
By default, date pads numeric fields with zeroes. 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
After any flags comes an optional field width, as a decimal number; then an optional modifier, which is either E to use the locale's alternate rep‐
resentations 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
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/> Report date translation bugs to <http://translationproject.org/team/>
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 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)],DATE 我們知道是命令的名稱,那么 (1) 代表什么?它代表的是“一般用戶可使用的命令”的意思。以下是常見的幾個數(shù)字的意義:
? ? ? ? 注:上表中的 1、5、8 這三個號碼特別重要,最好是將這三個數(shù)字所代表的意義背下來。
????????接下來,就是 man page 的內(nèi)容,基本上 man page 的內(nèi)容大致分成下面這幾個部分:
????????有些時候,你只記得該命令的部分關(guān)鍵詞,但是偏偏忘記了該命令的完整名稱,這個時候你要如何查出來你所想要知道的 man page 呢?
????????man -f 命令:
????????使用 -f 這個選項(xiàng)就可以取得更多與命令相關(guān)的信息,比如,執(zhí)行 man -f man:
[swadian@localhost ~]$ man -f man
man (1) - an interface to the on-line reference manuals
man (1p) - display system documentation
man (7) - macros to format man pages
????????上邊內(nèi)容中,第三行的 [man(7)] 表示有個 man(7) 的說明文件存在,但是也有個 man(1) 存在。那當(dāng)我們執(zhí)行 [man man] 的時候,到底是指向哪一個說明文件?其實(shí),你可以指定不同的文件,舉例來說,上表當(dāng)中的兩個 man 你可以這樣將它的文件顯示出來:
[swadian@localhost ~]$ man 1 man #展示man(1)的說明文件
[swadian@localhost ~]$ man 7 man #展示man(7)的說明文件
????????當(dāng)使用 [ man -f ] 命令] 時,man 只會找數(shù)據(jù)中的左邊那個命令的完整名稱,有一點(diǎn)不同都不行。
????????但如果我想要找的是關(guān)鍵詞呢?
????????man -k 命令:
????????比如,執(zhí)行 man -k grep 命令,你會發(fā)現(xiàn)具有 'grep ' 關(guān)鍵詞的命令都被打印出來了:
[swadian@localhost ~]$ man -k grep
bzgrep (1) - search possibly bzip2 compressed files for a regular expression
egrep (1) - print lines matching a pattern
fgrep (1) - print lines matching a pattern
grep (1) - print lines matching a pattern
grep (1p) - search a file for a pattern
#省略...
????????事實(shí)上,還有兩個命令與 man page 有關(guān),而這兩個命令是 man 的簡略寫法,這兩個命令如下:
[swadian@localhost ~]$ whatis grep #相當(dāng)于man -f
[swadian@localhost ~]$ apropos grep #相當(dāng)于man -k
4、man 命令輸出文檔漢化
? ? ? ? 一般來說,我們看?man 命令的輸出文檔默認(rèn)都是英語文檔,但對于初學(xué)者來說,可能會有些不習(xí)慣,那么,此時使用中文文檔就顯得簡單直觀多了。
? ? ? ? (1)首先,我們要從網(wǎng)上下載 man 的漢化包:
[root@localhost ~]# wget https://src.fedoraproject.org/repo/pkgs/man-pages-zh-CN/manpages-zh-1.5.1.tar.gz/13275fd039de8788b15151c896150bc4/manpages-zh-1.5.1.tar.gz
? ? ? ? (2)下載完成后,解壓 man 漢化包:
[root@localhost ~]# tar -xvf manpages-zh-1.5.1.tar.gz
? ? ? ? (3)然后,進(jìn)如解壓后的目錄,在安裝之前進(jìn)行一些配置:
[root@localhost ~]# cd manpages-zh-1.5.1/
[root@localhost manpages-zh-1.5.1]# ./configure --disable-zhtw --prefix=/usr/local/zhman
- --disable-zhtw:表示禁用繁體中文支持。軟件構(gòu)建時,相關(guān)的繁體中文的功能將被禁用。
- --prefix=/usr/local/zhman:指定軟件安裝的根目錄。在這個例子中,軟件將被安裝到 /usr/local/zhman 目錄下。prefix 選項(xiàng)通常用于指定軟件的安裝路徑。
? ? ? ? (4)執(zhí)行編譯:
[root@localhost manpages-zh-1.5.1]# make && make install
????????make 和 make install 是用于構(gòu)建和安裝軟件的兩個命令。
????????make 命令用于調(diào)用 Makefile 文件,執(zhí)行其中定義的構(gòu)建規(guī)則,編譯源代碼并生成可執(zhí)行文件,一旦通過 make 構(gòu)建成功,make install 用于將生成的可執(zhí)行文件和相關(guān)文件安裝到系統(tǒng)中。
????????(5)為了防止 man 中文版和英文版沖突,給 man 中文版起一個別名,并重新加載配置:
[root@localhost manpages-zh-1.5.1]# echo "alias cman='man -M /usr/local/zhman/share/man/zh_CN' " >>.bash_profile
[root@localhost manpages-zh-1.5.1]# source .bash_profile
????????接下來,就可以使用 cman 命令實(shí)現(xiàn) man 的功能了:
????????如上我們就對 man 命令進(jìn)行了漢化。文章來源:http://www.zghlxwxcb.cn/news/detail-820543.html
????????至此,全文結(jié)束。文章來源地址http://www.zghlxwxcb.cn/news/detail-820543.html
到了這里,關(guān)于【CentOS】Linux 在線幫助文檔命令:help、man 命令與文檔漢化的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!