开头需要加#!/bin/bash
[root@100xuni1 shell]# chmod a+x 01.sh
以#开头的行作为解释说明
脚本的名字以.sh结尾,用于区分这是一个shell脚本 执行方法有两种 chmod +x 1.sh; ./1.sh bash 1.sh 查看脚本执行过程 bash -x 1.sh
查看脚本是否语法错误 bash -n 1.sh
date命令是显示系统的当前的日期和时间,date在shll当中作用很大
date +%Y表示4位年后面加小y是2位年
date +%m月份+大M是分钟
date +%d日期+大D表示年月日
组合在一起date +%Y%m%d年月日
date +%F年月日带横杠
date +%H小时
date +%s时间戳+大S是秒
时间的标记
组合一起等同于大T
date +%w周几+大W是今年的第几周
表示日历的命令cal
date -d “-1 day” 一天前
date -d “-1 mouth” +%F一个月前
date -d “-1 year” +%F一年前
date -d “-1 hour” +%T一小时前
转载于:https://blog.51cto.com/8043410/2175024
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101425.html原文链接:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有