I have been looking for a way to archive our fileserver for some time now but have not found a working solution. The objective is to search through a directory and it's subdirectories for files not modified in the last x days. When there are no files found in the parent or its subdirectories, the entire parent directory should be archived (or at least printed to screen). Any suggestions are appreciated! Greetings, John

  • Is there any reason you are not using an existing backup solution such as borgbackup or similar? – Kusalananda Jun 19 '18 at 8:42
  • The goal is to move the parent directy to a nfs storage so we can clean up disk space on the server. With the backup solutions we use (like rsnapshot) that does not appear to be an option – John Jun 19 '18 at 8:55

A simple answer is to use the find command's "newer" argument, which finds any files newer than another file. Because what we want is actually the inverse, we'll need a script that counts the files that have been modified (i.e., are newer) and prints the name of the directory if NONE are found.

DATE=`date -d "-30 days"` #Calculate a date 30 days before today
touch -d "$DATE" /tmp/newer #Create a temp file with the calculated date

#Assume we're passing in a list of directories
#We could just as easily find any directory below a certain point without
#newer files by setting DIR=`find /what/ever/directory -type d`

for DIR in $* 
    MOD=`find "$DIR" -newer /tmp/newer | wc -l` #Count the number of newer files
    if [ "$MOD" -eq 0 ] 
        echo $DIR   # Nothing new in 30 days - Print the name of the Dir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.