Simulation Scenario:
In a directory, there are a large number of files generated in different days, and the name of the file does not have a date identification, how to divide the files by date into different folders.
According to the date the file was modified, mtime the file.
> Date
Tue Dec 14:04:04 CST 2016
Modifying the mtime of a file
/sysout> touch-c-t 12180010 file{101..200}
12180010 = December 18 0:10
/sysout> Find-mtime +1-type F | More
./file135
./file168
。。。
Verify the number of files
/sysout> Find-mtime +1-type F | Wc-l
100
/sysout> L file102
-rw-r--r--1 testuser testuser 0 Dec 00:10 file102
Date the backup file was created
> Date--date= ' 2days ago ' +%y%m%d
20161218
Backup scripts
> VI baklog.sh
#!/bin/bash
Logdir=/sysout
Logdate= ' Date--date= ' 2 days ago ' +%y%m%d '
bakdir=/backup/$LOGDATE
CD $LOGDIR
mkdir $BAKDIR
Find-mtime +1-name "file*"-exec mv {} $BAKDIR \;
This article is from the "Xiaoxiaozhou" blog, make sure to keep this source http://xiaoxiaozhou.blog.51cto.com/4681537/1885651
Differentiate && modify files by date Mtime