centos Linux:复制星期日创建的文件

rsaldnfx  于 2022-11-07  发布在  Linux
关注(0)|答案(1)|浏览(183)

我有一个脚本,并且只想复制在星期天创建的文件。
find /data/src/ -iname *.bak -mmin +3 -type f -exec cp {} -n -p -v /data/dest \;
在7.、14.、21.、28.创建的替代文件。
也许我们可以使用这个选项的文件名?
文件名如:

db1_backup_2021_10_27_233001_1582165.bak
db1_backup_2021_10_28_233001_1582165.bak
db2_backup_2021_10_28_233001_1582165.bak
...

多谢了!

rqdpfwrv

rqdpfwrv1#

可以使用find命令:

cp  `find . -type f -newermt '18 sep 2016 20:05:00'` FOLDER

或者:

cp `find -type f -printf '%Ta\t%p\n' | egrep "^(Sun)" | cut -f 2-`

请记住,这不是创建日期,而是最后修改日期

作为脚本文件的名称:


## declare an array variable put here the dates

eclare -a arr=("07" "14" "21" "28")

## now loop through the above array

for i in "${arr[@]}"
do
   echo "copying back from " + $i
   cp "db"*"_backup_"*"_"*"$i"*".bak" ./sundaysBackups/
   # or do whatever with individual element of the array
done

echo "ls in sundays"
ls ./sundaysBackups

您可以尝试使用文件名执行此操作:

cp "db"*"_backup_"*"_"*"_07_"*".bak" 
cp "db"*"_backup_"*"_"*"_14_"*".bak"
cp "db"*"_backup_"*"_"*"_21_"*".bak"
cp "db"*"_backup_"*"_"*"_28_"*".bak"

相关问题