我怎么能在UNIX-aix中获取date,并将ecah部分存储在variables中

我写batch file,我想比较修改时间(timstap)到两个文件夹,并复制最新的一个。 我不知道是否这个选项可用的目录是因为我不知道,所以我想获得的date,并存储在变化的每个部分来比较它

例如: –

得到datedate 11 5 2011 11:10:57

天= 11

一个月= 5

年= 2011

小时= 11

分= 10

secnd = 57

Bash提供了-nt比较运算符,如果一个文件比另一个文件更新,它将返回true。 这是一个说明这个function的脚本

 #!/bin/bash if [[ "$1" -nt "$2" ]] then echo "$1 is newer than $2 - copying $1" #do something else if [[ "$2" -nt "$1" ]] then echo "$2 is newer than $1 - copying $2" #do something else echo "$1 and $2 are the same time" #do nothing fi fi 

也许select – “find”更新可以做到这一点。

找 。 -newer directory -exec cp {} / new / location \;

PD我不会说英语

将datetime组件设置为shellvariables:

 eval $(date "+day=%d month=%m year=%Y hour=%H min=%M secnd=%S") 

为了比较date, 伊恩的答案是要走的路。