如何在linux中使用bash压缩90天的旧文件并将其移动到特定的文件夹

时间:2021-03-29 15:53:07

I have lots of files in my FILES folder. I want to zip the files that are 90days old then remove it from the FILES folder and move it to the ARCHIVES folder using bash in linux.

我的文件夹里有很多文件。我想要压缩那些90天前的文件,然后从文件文件夹中删除它,然后在linux中使用bash将它移动到存档文件夹。

This is my folder structure:

这是我的文件夹结构:

root@user:/var/FILES

root@user:/ var /文件

root@user:/var/ARCHIVES

root@user:/ var /档案

I have created a script to zip a file but don't know how to specify the age of the file

我创建了一个用于压缩文件的脚本,但是不知道如何指定文件的年龄

zip -r zipped.zip *.*

so i coded something like

我写了一些

FILE=find *.* -mtime +90
zip -r zipped.zip $FILE

but only returns error. Thanks

但只返回错误。谢谢

2 个解决方案

#1


2  

You can use:

您可以使用:

find . -mtime +90 -exec zip zipped.zip '{}' +

EDIT If you want move zipped file to an archive folder then you can do:

编辑,如果你想移动压缩文件到档案文件夹,那么你可以做:

find . -mtime +90 -exec zip zipped.zip '{}' + && mv zipped.zip /var/ARCHIVES

#2


0  

you can try find

你可以试着找

find /var/FILES/ -type f -mtime +90 -exec zip -r zipped.zip {} \; -exec mv {} /var/ARCHIVES \;

Not sure whether I understand you correct, if you want to save zipped.zip in /var/ARCHIVES just use this:

不知道我是否理解你的意思,如果你想保存拉链。zip in /var/ archive只需使用这个:

find /var/FILES/ -type f -mtime +90 -exec zip -r /var/ARCHIVES/zipped.zip {} \;

#1


2  

You can use:

您可以使用:

find . -mtime +90 -exec zip zipped.zip '{}' +

EDIT If you want move zipped file to an archive folder then you can do:

编辑,如果你想移动压缩文件到档案文件夹,那么你可以做:

find . -mtime +90 -exec zip zipped.zip '{}' + && mv zipped.zip /var/ARCHIVES

#2


0  

you can try find

你可以试着找

find /var/FILES/ -type f -mtime +90 -exec zip -r zipped.zip {} \; -exec mv {} /var/ARCHIVES \;

Not sure whether I understand you correct, if you want to save zipped.zip in /var/ARCHIVES just use this:

不知道我是否理解你的意思,如果你想保存拉链。zip in /var/ archive只需使用这个:

find /var/FILES/ -type f -mtime +90 -exec zip -r /var/ARCHIVES/zipped.zip {} \;