`
hoodbc
  • 浏览: 113222 次
  • 性别: Icon_minigender_1
  • 来自: 南宁
社区版块
存档分类
最新评论

[转]shell:date 常用方式

阅读更多

在linux下获取时间字符串
命令 date
# 以yyyymmdd格式输出23天之前现在这个时刻的时间
$ date +%Y%m%d –date=’23 days ago’

$ date -u
Thu Sep 28 09:32:04 UTC 2006

$ date -R
Thu, 28 Sep 2006 17:32:28 +0800

# 测试十亿分之一秒
$ date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’
20060928 17:44:20.906805000
20060928 17:44:20.909188000
20060928 17:44:20.911535000
20060928 17:44:20.913886000
date 参考
$ 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.

-d, –date=STRING display time described by STRING, not `now’
# such as ‘n days ago |1 month ago|n years ago’
-f, –file=DATEFILE like –date once for each line of DATEFILE
-ITIMESPEC, –iso-8601[=TIMESPEC] output date/time in ISO 8601 format.
TIMESPEC=`date’ for date only,
`hours’, `minutes’, or `seconds’ for date and
time to the indicated precision.
–iso-8601 without TIMESPEC defaults to `date’.
-r, –reference=FILE display the last modification time of FILE
-R, –rfc-2822 output RFC-2822 compliant date string
-s, –set=STRING set time described by STRING
-u, –utc, –universal print or set Coordinated Universal Time
–help display this help and exit
–version output version information and exit

FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:

%% 输出%符号 a literal %
%a 当前域的星期缩写 locale’s abbreviated weekday name (Sun..Sat)
%A 当前域的星期全写 locale’s full weekday name, variable length (Sunday..Saturday)
%b 当前域的月份缩写 locale’s abbreviated month name (Jan..Dec)
%B 当前域的月份全称 locale’s full month name, variable length (January..December)
%c 当前域的默认时间格式 locale’s date and time (Sat Nov 04 12:02:33 EST 1989)
%C n百年 century (year divided by 100 and truncated to an integer) [00-99]
%d 两位的天 day of month (01..31)
%D 短时间格式 date (mm/dd/yy)
%e 短格式天 day of month, blank padded ( 1..31)
%F 文件时间格式 same as %Y-%m-%d
%g the 2-digit year corresponding to the %V week number
%G the 4-digit year corresponding to the %V week number
%h same as %b
%H 24小时制的小时 hour (00..23)
%I 12小时制的小时 hour (01..12)
%j 一年中的第几天 day of year (001..366)
%k 短格式24小时制的小时 hour ( 0..23)
%l 短格式12小时制的小时 hour ( 1..12)
%m 双位月份 month (01..12)
%M 双位分钟 minute (00..59)
%n 换行 a newline
%N 十亿分之一秒 nanoseconds (000000000..999999999)
%p 大写的当前域的上下午指示 locale’s upper case AM or PM indicator (blank in many locales)
%P 小写的当前域的上下午指示 locale’s lower case am or pm indicator (blank in many locales)
%r 12小时制的时间表示(时:分:秒,双位) time, 12-hour (hh:mm:ss [AP]M)
%R 24小时制的时间表示 (时:分,双位)time, 24-hour (hh:mm)
%s 自基础时间 1970-01-01 00:00:00 到当前时刻的秒数 seconds since `00:00:00 1970-01-01 UTC’ (a GNU extension)
%S 双位秒 second (00..60); the 60 is necessary to accommodate a leap second
%t 横向制表位(tab) a horizontal tab
%T 24小时制时间表示 time, 24-hour (hh:mm:ss)
%u 数字表示的星期(从星期一开始 1-7)day of week (1..7); 1 represents Monday
%U 一年中的第几周星期天为开始 week number of year with Sunday as first day of week (00..53)
%V 一年中的第几周星期一为开始 week number of year with Monday as first day of week (01..53)
%w 一周中的第几天 星期天为开始 0-6 day of week (0..6); 0 represents Sunday
%W 一年中的第几周星期一为开始 week number of year with Monday as first day of week (00..53)
%x 本地日期格式 locale’s date representation (mm/dd/yy)
%X 本地时间格式 locale’s time representation (%H:%M:%S)
%y 两位的年 last two digits of year (00..99)
%Y 年 year (1970…)
%z RFC-2822 标准时间格式表示的域 RFC-2822 style numeric timezone (-0500) (a nonstandard extension)
%Z 时间域 time zone (e.g., EDT), or nothing if no time zone is determinable

By default, date pads numeric fields with zeroes. GNU date recognizes
the following modifiers between `%’ and a numeric directive.

`-’ (hyphen) do not pad the field
`_’ (underscore) pad the field with spaces
分享到:
评论

相关推荐

    linux 常用shell命令

    个人日常工作中,常用shell命令总结,从简单到复杂,各种操作对于数据分析人员来说也有一定的帮助

    实验一shell实验报告

    date, mail, write, man, ls, cat, mv, grep, tail, head, cp, wc, pwd, who等; 2、使用vi编辑器编辑文件,熟悉vi编辑器的各种操作模式和常用命令。 3、使用vi编辑器编写一段Shell程序,取名为mycal,实现与Linux中...

    shell:我在unixlinux下积累的常用工具

    我在unixtools下积累的常用工具 PS,这里所有的工具都是给淘宝环境下使用,如果你不能理解脚本中的含义,请勿自己使用,谢谢呐。 Java线程过高问题排查 curl -sLk ...

    shell 编程指南pdf

    1.8.2 常用的umask值 11 1.9 符号链接 12 1.9.1 使用软链接来保存文件的多个映像 12 1.9.2 符号链接举例 12 1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 ...

    shell入门经典资料

    date who ls cat wc ln basename dirname sort uniq cut paste tr grep 練習用的資料檔 常用的特殊字元 一個命令列執行好幾個命令 命令列郵寄帶檔的方法 本節習題 5.設定變數 設定變數的方法 取得變數的內容 取消

    编写shell脚本的常用知识点

    编写shell脚本的常用知识点 对字符串的处理 将字符串分割成数组 path=/back/task/subtask/partition/db/table OLD_IFS=\$IFS IFS=/ data=(\$path) IFS=\$OLD_IFS for i in \${!data[@]};do echo \$i=>\${data[i]} ...

    debian操作系统常用命令.docx

    logout, login: 登录shell的登录和注销命令 5. pwd: print or set the system date and time 6. more, less, head tail: 显示或部分显示文件内容. 7. lp/lpstat/cancel, lpr/lpq/lprm: 打印文件. 8. 更改文件权限:...

    LINUX与UNIX SHELL编程指南(很全)

    1.8.2 常用的umask值 11 1.9 符号链接 12 1.9.1 使用软链接来保存文件的多个映像 12 1.9.2 符号链接举例 12 1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 ...

    操作系统实验报告,观察Linux的行为、SHELL编程

    实验一:观察Linux的行为、SHELL编程 1.实验目的 了解Linux proc文件系统; 加深对Linux系统的理解; 增强Linux系统管理知识。...date, man, ls, cat, mv, grep, tail, head, cp, wc, pwd, who等;

    shell语言学习入门详解

    shell 入门,常用命令 cat 文件名 输出文件内容到基本输出(屏幕 or 加>fileName 到另一个文件) cb 格式化源代码 chmod //change mode,改变文件的权限 cp copy date 当前的时间和日期 echo $abc 在变量赋值之后,...

    LINUX and SHELL 自学总结

    可以当查询手册使用,因为是自己一点一点积累的,所以多要些资源分 一、各种循环命令 3 1. #WHILE循环用法 3 2. #UNTIL循环用法 3 3. #FOR循环用法: 3 二、各种条件语句 4 1. #IF语句用法 4 ...4. #DATE命令的使用 12

    绝版经典《Linux与UNIX Shell编程指南》

    1.8.2 常用的umask值 11 1.9 符号链接 12 1.9.1 使用软链接来保存文件的多个映像 12 1.9.2 符号链接举例 12 1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 ...

    shell 调度的常用命令

    了解 shell 脚本 单个任务下,常见的几个问题 日期处理 路径问题 变量替换 如何记录任务的耗时 后台跑数据问题 日期处理 日期处理的场景 日期处理是关于如何获取日期以及格式化日期。举个最常见的例子,销售类报表是...

    shell教程-30章,下了之后会让你大吃一惊,相当好

    1.8.2 常用的umask值 11 1.9 符号链接 12 1.9.1 使用软链接来保存文件的多个映像 12 1.9.2 符号链接举例 12 1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 ...

    LINUX与UNIX SHELL编程指南 高清PDF

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 shell...

    Linux与Unix Shell编程指南(PDF格式,共30章)

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...

    linux shell 编程教程

    1.8.2 常用的umask值 11 1.9 符号链接 12 1.9.1 使用软链接来保存文件的多个映像 12 1.9.2 符号链接举例 12 1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 ...

    Linux shell编程指南

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...

    Linux教程,主要内容:Linux 命令、Linux 系统运维、软件运维、精选常用Shell脚本.zip

    linux教程: 查看 Linux 命令帮助信息 - 关键词:help, whatis, info, which, where...Linux 系统管理 - 关键词:reboot, exit, shutdown, date, mount, umount, ps, kill, systemctl, service, crontab Linux 网络管理

    shell编程和unix命令

    本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...

Global site tag (gtag.js) - Google Analytics