Moh*_*deh 1 unix bash command-line-interface aix
我编写批处理文件,我想将修改时间(timstap)与两个文件夹进行比较并复制最新的一个。我不知道这个选项可用目录是否是因为我不知道。所以我想获取日期并将每个部分存储在变量中以进行比较
例子 :-
获取日期date
11 5 2011 11:10:57
天=11
月=5
年=2011
小时=11
最小值=10
秒=57
Bash 提供了-nt
比较运算符,如果一个文件比另一个文件新,则返回 true。这是一个说明此功能的脚本
#!/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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
624 次 |
最近记录: |