02-2017-11-08-练习-日期开机关机

练习1-date

1 、显示当前时间,格式:2016-06-18 10:20:30

[root@centos6 ~]# date "+%Y-%m-%d %H:%M:%S"
2017-11-10 09:20:34

2 、显示前天是星期几

[root@centos6 ~]# date
Fri Nov 10 09:27:41 CST 2017
[root@centos6 ~]# date -d  "@"$(echo $(date +%s) -  60*60*24*2 |bc) +%w
3
[root@centos6 ~]# date -d  "-2 day" +%w
3

3 、设置当前日期为2019-08-07 06:05:10

[root@centos6 ~]# date 080706052019.10
Wed Aug  7 06:05:10 CST 2019
[root@centos6 ~]# date
Wed Aug  7 06:05:12 CST 2019
[root@centos6 ~]# date "+%Y-%m-%d %H:%M:%S"
2019-08-07 06:05:42

练习2-mingetty,shutdown

1、在本机字符终端登录时,除显示原有信息外,再显示当前登录终端号,主机名和当前时间 我们使用man mingetty可以获取到如下的帮助信息。

-d insert current day (localtime), 插入当前日期
-l insert line on which mingetty is running,终端类型
-m inserts machine architecture (uname -m),机器架构
-n inserts machine’s network node hostname (uname -n),主机名
-o inserts domain name,域名
-r inserts operating system release (uname -r),版本号
-t insert current time (localtime),时间
-s inserts operating system name,操作系统名字
-u resp. U the current number of users which are currently loggedin. 显示登陆用户数量
-v inserts operating system version (uname -v).操作系统版本

修改文件如下即可

[root@centos6 ~]# cat /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m
current time: \d \t
hostname : \n
tty:    \l

2、今天18:30自动关机,并提示用户

[root@centos6 ~]# shutdown 18:30 "computer will close"

Broadcast message from root@centos6.magedu.com
        (/dev/pts/1) at 6:28 ...

The system is going down for maintenance in 722 minutes!
computer will close