Linux的日期与时间

基本语法

1、date(显示当前时间)
2、date +%Y (显示当前年份)
3、date +%m (显示当前月份)
4、date +%d (显示当前是哪一天)
5、date “+%Y-%m-%d% %H:%M:%s” (显示年月日时分秒)

时间命令

  • date
    查看当前系统时间
  • cal 查看日历
    cal 2020
  • 修改时间
    date -s 11:11:11
    date -s 2019-11-11
    date -s ‘2019-11-11 11:11:11’

日期自动同步

  • 自动同步时间
    yum install ntp -y
    ntpdate cn.ntp.org.cn

  • 本地搭建NTP服务

    • 开启本地NTP服务器
      service ntpd start
    • vi /etc/ntp.conf

#======权限控制=======
restrict default kod nomodify notrap nopeeer noquery		拒绝ipv4用户
restrict -6 default kod nomodify notrap nopeeer noquery		拒绝ipv6用户
restrict 210.72.145.44	授权国家授时中心服务器访问本地NTP
restrict 133.100.11.8	授权133.100.11.8访问本地NTP
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.188.2 mask 255.255.255.0 nomodify	本地网段授权访问
#=======源服务器=========
server cn.ntp.org.cn prefer	指定上级更新时间服务器,优先使用这个地址
#=======差异分析=========
driftfile /var/lib/ntp.drift
key		/etc/ntp.keys

客户端同步时间
ntpdate 192.168.188.100

命令执行时间统计

#!/bin/bash
start=$(date +%s)
nmap man.linuxde.net &>	/dev/nullend=$(date +%s)
difference=$(( end - start ))
echo $difference seconds

cal指令

查看日历指令
cal (查看本月日历)
cal 年份 (查看本年日历)


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部