linux,只复制某个日期之前的文件

use*_*171 1 linux copy

是否有命令只复制某个日期之前的文件,比如 20120901?此外,我想使用 cp -p 功能(例如,保留原始时间戳)。

Sco*_*ack 6

是的,您应该能够通过触摸和查找的组合来做到这一点。

# Create a file with the desired timestamp
touch -d 20120901 /tmp/timefile

# Find all files older than that and act on them
find $PATH -type -f -and -not -newer /tmp/timefile -print0 | xargs -0 -i % cp -p % /new/location
Run Code Online (Sandbox Code Playgroud)

因此,这样做的作用是找到目录下所有在$PATH2012 年 9 月 1 日 00:00:00 之前修改过的文件,并将它们全部复制到目录中/new/location