一、命令帮助
1、查看bash内部命令帮助
help cd
2、命令 --help
[root@node13 ~]# date ——help 示例如下:date [OPTION]... [+FORMAT] 表明cat后面可以加上多个可选的选项以及多个可选的文件参 数 下面是对于命令的语法的一些符号的说明: [] :表示的是可选 ...: 表示的可以存在多个参数 |表示是可选的 <>:必填 {}:表示作为一个整体存在的
3、man用来提供在线帮助,使用权限是所有用户。使用man命令可以调阅其中的帮助信息,非常方便实用。
man command 选项:-C config_file:指定配置文件man.conf,缺省值 是/etc/man.conf`
执行
man date
4、在man命令帮助信息的界面中,所包含的常用操作按键如下:
man命令的帮助信息的结构如下:
区段1:用户指令,查看命令的帮助 区段2:系统调用,查看可被内核调用的函数的帮助 区段3:程序库调用,查看函数和函数库的帮助 区段4:设备,查看特殊文件的帮助(主要是/dev目录下的文件) 区段5:文件格式,查看配置文件的帮助 区段6:游戏,查看游戏的帮助 区段7:杂项,惯例与协议等,例如Linux文件系统、网络协议、ASCII code等等的说明 区段8:系统指令,查看系统管理员可用的命令的帮助 区段9:内核内部指令,查看内核相关文件的帮助 使用如下命令可以知道某个命令在man的哪个区段有相关帮助文档: [root@node13 ~]# whatis man man (7) - macros to format man pages man (1) - an interface to the on-line reference manuals man (1p) - display system documentation [root@node13 ~]# man -f man man (7) - macros to format man pages man (1) - an interface to the on-line reference manuals man (1p) - display system documentation [root@node13 ~]# man 1 man [root@node13 ~]# man 7 man
二、date命令
date命令用于显示或设置系统的时间与日期,语法格式为: date [OPTION]... [+FORMAT]
用户只需在强大的date命令后输入以 + 号开头的参数,即可按照指定格式来输出系统的时间或日期,这
样在日常工作时便可以把备份数据的命令与指定格式输出的时间结合到一起。
1、按照默认格式查看当前系统时间的date命令
[root@ls_nfqZ8Onc ~]# date Wed Jul 13 17:50:17 CST 2022
2、date --date=String命令可以自定义显示时间
语法 date --date=String String代表修改的时间
样例:
[root@ls_nfqZ8Onc ~]# date --date='2022-10-01' Sat Oct 1 00:00:00 CST 2022
3、–debug命令注释解析的日期,并警告可疑的 stderr 用法
[root@ls_nfqZ8Onc ~]# date --date='2020-7-13' --debug date: parsed date part: (Y-M-D) 2020-07-13 date: input timezone: system default date: warning: using midnight as starting time: 00:00:00 date: starting date/time: '(Y-M-D) 2020-07-13 00:00:00' date: '(Y-M-D) 2020-07-13 00:00:00' = 1594569600 epoch-seconds date: timezone: system default date: final: 1594569600.000000000 (epoch-seconds) date: final: (Y-M-D) 2020-07-12 16:00:00 (UTC) date: final: (Y-M-D) 2020-07-13 00:00:00 (UTC+08) Mon Jul 13 00:00:00 CST 2020
4、-I[FMT], --iso-8601[=FMT]命令
FMT='date' for date only (the default), 'hours', 'minutes', 'seconds', or 'ns'
以 ISO 8601 格式输出日期/时间。
FMT=“日期”仅用于日期(默认值)、“小时”、“分钟”、“秒”或“ns”
将日期和时间设置为指示的精度。
ISO 8601是全世界日期和时间相关的数据交换的国际标准。这个标准的目标是在全世界范围的通信中提供格式良好的、无歧义的时间和日期表示。
[root@ls_nfqZ8Onc ~]# date -I 2022-07-13 [root@ls_nfqZ8Onc ~]# date --iso-8601='' date: ambiguous argument ‘’ for ‘--iso-8601’ Valid arguments are: - ‘hours’ - ‘minutes’ - ‘date’ - ‘seconds’ - ‘ns’ [root@ls_nfqZ8Onc ~]# date --iso-8601='date' 2022-07-13 [root@ls_nfqZ8Onc ~]# date --iso-8601='hours' 2022-07-13T18+08:00 [root@ls_nfqZ8Onc ~]# date --iso-8601='ns' 2022-07-13T18:17:34,742412256+08:00
5、-R命令
RFC 5322 格式的输出日期和时间
-R
[root@ls_nfqZ8Onc ~]# date -R Wed, 13 Jul 2022 18:21:55 +0800
–rfc-email
–rfc-3339=FMT
FMT=‘date’, ‘seconds’, or ‘ns’
[root@ls_nfqZ8Onc ~]# date --rfc-email Wed, 13 Jul 2022 18:23:03 +0800 [root@ls_nfqZ8Onc ~]# date --rfc-3339=date 2022-07-13 [root@ls_nfqZ8Onc ~]# date --rfc-3339=ns 2022-07-13 18:25:09.650539274+08:00
-r, --reference=FILE
显示文件的上次修改时间
[root@ls_nfqZ8Onc ~]# date -r flie Wed Jul 13 18:27:17 CST 2022 [root@ls_nfqZ8Onc ~]# date Wed Jul 13 18:28:47 CST 2022
6、-s, --set=STRING命令
字符串描述的设置时间
[root@ls_nfqZ8Onc ~]# date -s'2020-11-11 12:00:01' Wed Nov 11 12:00:01 CST 2020
7、-u, --utc, --universal命令
打印或设置协调世界时 (UTC)
[root@ls_nfqZ8Onc ~]# date -u Wed Nov 11 04:03:04 UTC 2020
8、date格式控制输出。
%% 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 %q quarter of year (1..4) %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
例如:
三、timedatectl命令
格式:
timedatectl [OPTIONS...] COMMAND ...
-h --help Show this help message --version Show package version --no-pager Do not pipe output into a pager --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --adjust-system-clock Adjust system clock when changing local RTC mode --monitor Monitor status of systemd-timesyncd -p --property=NAME Show only properties by this name -a --all Show all properties, including empty ones --value When showing properties, only print the value Commands: status Show current time settings show Show properties of systemd-timedated set-time TIME Set system time set-timezone ZONE Set system time zone list-timezones Show known time zones set-local-rtc BOOL Control whether RTC is in local time set-ntp BOOL Enable or disable network time synchronization
timedatectl命令用于设置系统的时间
查看系统时间与时区:
[root@ls_nfqZ8Onc ~]# timedatectl Local time: Wed 2020-11-11 12:15:14 CST Universal time: Wed 2020-11-11 04:15:14 UTC RTC time: Wed 2022-07-13 10:48:48 Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: no NTP service: active RTC in local TZ: no
更改时区到America/Los_Angeles
[root@ls_nfqZ8Onc ~]# timedatectl set-timezone America/Los_Angeles [root@ls_nfqZ8Onc ~]# timedatectl Local time: Tue 2020-11-10 20:22:09 PST Universal time: Wed 2020-11-11 04:22:09 UTC RTC time: Wed 2022-07-13 10:55:11 Time zone: America/Los_Angeles (PST, -0800) System clock synchronized: no NTP service: active RTC in local TZ: no
可以手动的修改系统日期和时间:
[root@kongd ~]# timedatectl set-time 2021-05-18 [root@kongd ~]# timedatectl set-time 9:30 [root@kongd ~]# date Tue May 18 09:30:01 CST 2021
四、file和stat命令的使用文件类型:代表字符,以及英文
文件类型
file 展示文件类型
stat 展示文件状态