Linux,只有在某个date之前复制文件

是否有一个命令只在某个date之前复制文件,比如20120901? 此外,我想用cp -p能力来做(例如保留原始时间戳)。

是的,你应该能够通过触摸和查找的结合来实现。

# 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 

那么这个function是在2012年9月1日00:00:00之前查找目录$PATH下的所有文件,并将它们全部复制到目录/new/location