Omi*_*uin 18 find recursive files
我需要根据一年移动文件。我使用了find
命令
find /media/WD/backup/osool/olddata/ -mtime +470 -exec ls -lrth {} \;|sort -k6
Run Code Online (Sandbox Code Playgroud)
但是要成功执行此命令,我需要知道mtime
现在的确切值470 只是一个猜测。意味着如果我可以给出 2012 年,它会给我只与 2012 相关的文件。
所以我需要关于如何的建议
根据年份(例如 2012)查找文件并将它们移动到其他目录。
OS release 5.2
FIND version
GNU find version 4.2.27
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX
Run Code Online (Sandbox Code Playgroud)
Ant*_*hon 45
您想将该-newermt
选项用于find
:
find /media/WD/backup/osool/olddata/ -newermt 20120101 -not -newermt 20130101
Run Code Online (Sandbox Code Playgroud)
获取2012年修改时间的所有文件。
如果您的发现不支持,-newermt
您还可以执行以下操作以防止使用偏移计算:
touch -d 20120101 /var/tmp/2012.ref
touch -d 20130101 /var/tmp/2013.ref
find /media/WD/backup/osool/olddata/ -newer /var/tmp/2012.ref -not -newer /var/tmp/2013.ref
Run Code Online (Sandbox Code Playgroud)
-newerXY reference
Compares the timestamp of the current file with reference. The
reference argument is normally the name of a file (and one of
its timestamps is used for the comparison) but it may also be a
string describing an absolute time. X and Y are placeholders
for other letters, and these letters select which time belonging
to how reference is used for the comparison.
...
m The modification time of the file reference
t reference is interpreted directly as a time
Run Code Online (Sandbox Code Playgroud)
touch --date=2011-12-31T23:59:59 start
touch --date=2012-12-31T23:59:59 stop
find / -newer start \! -newer stop -printf %Tx" "%p\\n
Run Code Online (Sandbox Code Playgroud)
-exec ls
没有任何意义。
根据手册页, -mtime 的参数是您要查找的天数。您可以用来date +%j
查找自今年 1 月 1 日以来的天数。