[英]In linux shell, How to cp/rm files by time?
In linux shell, When I run在 linux shell 中,当我运行时
ls -al -t
that show the time of files.显示文件的时间。
How to cp/rm files by time?如何按时间cp/rm文件? just like copy all the files that created today or yesterday.
就像复制今天或昨天创建的所有文件一样。 Thanks a lot.
非常感谢。
Depending on what you actually want to do, find
provides -[acm]time
options for finding files by accessed, created or modified dates, along with -newer
and -min
.根据您实际想要执行的操作,
find
提供-[acm]time
选项,用于按访问、创建或修改日期查找文件,以及-newer
和-min
。 You can combine them with -exec
to copy, delete, or whatever you want to do.您可以将它们与
-exec
结合使用以进行复制、删除或任何您想要执行的操作。 For example:例如:
find -maxdepth 1 -mtime +1 -type f -exec cp '{}' backup \;
Will copy all the regular files in the current directory more than 1 day old to the directory backup
(assuming the directory backup
exists).将当前目录中超过 1 天的所有常规文件复制到目录
backup
(假设目录backup
存在)。
Simple Example简单例子
find /path/to/folder/ -mtime 1 -exec rm {} \; // Deletes all Files modified yesterday
For more examples google for bash find time or take a look here有关更多示例,请搜索 google for bash find time或查看此处
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.