根据目录创建日期复制目录

根据目录创建日期复制目录

您能告诉我任何命令来对在特定日期(即昨天)修改过(或创建,尽管 Linux 没有显示)的目录进行排序/复制/删除并且它们位于另一个目录内吗?

答案1

我将使用find并指定-mtime

例如

cd /var/log/apache2
find *.log -mtime -1  -exec ls -l --time-style=iso {} \;

将输出以下内容:

-rw-r----- 1 root adm 440 09-10 20:00 错误.log

-rw-r----- 1 根管理员 3944602 09-11 02:08 other_vhosts_access.log

如果我想复制它们,我会执行以下操作:

查找 *.log -mtime -1 -exec cp -v {} /tmp/ \;

将输出:

error.log' ->/tmp/error.log'

other_vhosts_access.log' ->/tmp/other_vhosts_access.log'

有关mtime的更多信息:

For example:

find . -mtime 0   # find files modified between now and 1 day ago
                  # (i.e., within the past 24 hours)
find . -mtime -1  # find files modified less than 1 day ago
                  # (i.e., within the past 24 hours, as before)
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modified between
                          # 6 and 9 minutes ago

来源:http://content.hccfl.edu/pollock/unix/findcmd.htm

答案2

您可以使用管道命令来实现这一点。希望这对您有所帮助。

rmdir `ls -lt | grep -v "\`date '+%h %d'\`" | awk '{print $NF}'` 

相关内容