关闭

[Linux]时间相关命令

标签: linuxdatestattouch
808人阅读 评论(0) 收藏 举报
分类:

查看系统时间

[mycentos64@localhost so]$ 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'
  -f, --file=DATEFILE       like --date once for each line of DATEFILE
  -r, --reference=FILE      display the last modification time of FILE
  -R, --rfc-2822            output date and time in RFC 2822 format
      --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.
                            TIMESPEC=`date', `seconds', or `ns' for
                            date and time to the indicated precision.
  -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 (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., 21)
  %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 ( 0..23)
  %l   hour ( 1..12)
  %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
  %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 timezone (e.g., -0400)
  %:z  +hh:mm numeric timezone (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

After any flags comes an optional field width, as a decimal number;
then an optional modifier, which is either
E to use the locale's alternate representations if available, or
O to use the locale's alternate numeric symbols if available.

Report bugs to <bug-coreutils@gnu.org>.

查看文件信息

[mycentos64@localhost so]$ stat --help
Usage: stat [OPTION] FILE...
Display file or file system status.

  -L, --dereference     follow links
  -Z, --context         print the security context information if available
  -f, --file-system     display file system status instead of file status
  -c  --format=FORMAT   use the specified FORMAT instead of the default;
                          output a newline after each use of FORMAT
      --printf=FORMAT   like --format, but interpret backslash escapes,
                          and do not output a mandatory trailing newline.
                          If you want a newline, include \n in FORMAT.
  -t, --terse           print the information in terse form
      --help     display this help and exit
      --version  output version information and exit

The valid format sequences for files (without --file-system):

  %a   Access rights in octal
  %A   Access rights in human readable form
  %b   Number of blocks allocated (see %B)
  %B   The size in bytes of each block reported by %b
  %d   Device number in decimal
  %D   Device number in hex
  %f   Raw mode in hex
  %F   File type
  %g   Group ID of owner
  %G   Group name of owner
  %h   Number of hard links
  %i   Inode number
  %n   File name
  %N   Quoted file name with dereference if symbolic link
  %o   I/O block size
  %s   Total size, in bytes
  %t   Major device type in hex
  %T   Minor device type in hex
  %u   User ID of owner
  %U   User name of owner
  %x   Time of last access
  %X   Time of last access as seconds since Epoch
  %y   Time of last modification
  %Y   Time of last modification as seconds since Epoch
  %z   Time of last change
  %Z   Time of last change as seconds since Epoch

Valid format sequences for file systems:

  %a   Free blocks available to non-superuser
  %b   Total data blocks in file system
  %c   Total file nodes in file system
  %d   Free file nodes in file system
  %f   Free blocks in file system
  %C   Security context in SELinux
  %i   File System ID in hex
  %l   Maximum length of filenames
  %n   File name
  %s   Block size (for faster transfers)
  %S   Fundamental block size (for block counts)
  %t   Type in hex
  %T   Type in human readable form

NOTE: your shell may have its own version of stat, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report bugs to <bug-coreutils@gnu.org>.

修改文件时间

[mycentos64@localhost so]$ touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
  --time=WORD            change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

If a FILE is -, touch standard output.

Report bugs to <bug-coreutils@gnu.org>.
0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

linux 进程管理相关命令汇总

## processes 进程管理 ##ps查看当前系统执行的线程列表,进行瞬间状态,不是连续状态,连续状态需要使用top名称查看 更多常用参数请使用 man ps查看 ps ##显示所有...
  • zhongweijian
  • zhongweijian
  • 2015-06-12 10:32
  • 2228

Linux常用网络命令

与Linux网络相关的文件(1)/etc/sysconfig/network功能在于设置主机名称和是否可以启动整个网络(2)/etc/sysconfig/network-scripts/ifcfg-e...
  • Gavin__Zhou
  • Gavin__Zhou
  • 2016-03-14 19:17
  • 1011

Linux时间相关命令

在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,熟练运用date命令来表示自己想要表示的时间,肯定可以给自己的工作带来诸多方便。 1.命令格式:   date...
  • lee244868149
  • lee244868149
  • 2015-03-03 17:02
  • 388

LINUX系统时间怎么设置同步脚本或命令?

LINUX系统时间怎么设置同步脚本或命令?Linux系统和windows不同的地方,如果时间和网络时间差距太大的话。可能会导致程序,进程启动不了。所以linux系统时间同步显得尤为重要,咗嚛本经验以c...
  • it_xiuxiu
  • it_xiuxiu
  • 2016-08-23 11:16
  • 1763

Linux 常用网络命令介绍

Linux 的网络功能相当的强悍,一时之间我们也无法完全的介绍所有的网络命令, 这个章节主要的目的在介绍一些常见的网络命令而已。至于每个命令的详细用途将在后续服务器架设时, 依照命令的相关性来进行说明...
  • wzyzzu
  • wzyzzu
  • 2016-01-21 16:07
  • 1167

Linux中设置和同步时间

准确的系统时间是稳定服务的基础,本文介绍与时间相关的Linux命令,以及如何为自己的Linux服务器维护准确的时间。 时间 一台Linux服务器有两个时间源,一个是硬件时间,即服务器硬件CMOS维...
  • DViewer
  • DViewer
  • 2016-10-30 16:00
  • 3995

Linux 基本用户和组命令

Linux 基本用户和组命令   1有关用户的命令 (1).新增用户     Useradd  + 用户名    (2).查看用户是否存在     &...
  • qi_700
  • qi_700
  • 2017-01-08 16:48
  • 710

【Linux】Linux下使用stat命令所显示出来的三个时间

在linux系统下,使用stat(显示inode信息)命令可以查看一个文件的某些信息,我们先来尝试一下。 简单的介绍一下stat命令显示出来的文件其他信息: - File:显示文件名 - S...
  • pointer_y
  • pointer_y
  • 2017-01-11 21:28
  • 2373

Linux下ntpdate时间同步

原文地址:http://gaoxingf.blog.51cto.com/612518/121959   作者:高兴F Linux下ntpdate时间同步 Ntp服务器安装配置 RedHat服务器可以下...
  • achang21
  • achang21
  • 2015-06-30 11:43
  • 52523

Linux指令-cd命令和与时间相关的命令

Linux指令    1.cd命令     名称:cd     使用对象:所有使用者     命令格式:cd [dirName] (cd和目录间使用空格分隔)     作用:切换当前目录至dirNam...
  • agate_zhang
  • agate_zhang
  • 2017-07-15 15:34
  • 151
    个人资料
    • 访问:83057次
    • 积分:1748
    • 等级:
    • 排名:千里之外
    • 原创:89篇
    • 转载:15篇
    • 译文:3篇
    • 评论:8条
    博客专栏
    最新评论