samoot04
samoot04

Reputation: 41

find directory older than 3 days and zip all files in it

Can i find any directories with a condition like older than 3 days

and zip them then delete the directories?

I have 2 solutions.

  1. zip all directories in 1 zip under working directory

    I tried

    zip -rm ${WORKDIR}/date +%Y%m%d -d "${DAY_TO_ZIP} days ago".zipfind ${WORKDIR} -daystart -mtime +${DAY_TO_ZIP} -type d ! -name "*.zip"``

    this command will zip all files include non-directory file.

  2. 1 directory 1 zip same path with a directory

thank you very much

Upvotes: 1

Views: 9304

Answers (2)

aymen messaoudi
aymen messaoudi

Reputation: 57

find ./ -mtime +x -print -exec gzip {} ;

Upvotes: 0

Rakib
Rakib

Reputation: 2086

Execute bellow command to find all directory older than 3 days and zip all file

        # find / -mtime +3 -type d -exec zip -r zipfile.zip {} +

-mtime +3 means you are looking for a file modified 3 days ago.

-mtime -3 means less than 3 days.

-mtime 3 If you skip + or – it means exactly 3 days.

Finally If you delete all directory then execute bellow command

       # find / -mtime +3 -type d -exec rm -f {} \;

Upvotes: 2

Related Questions