I'm running an unnecessarily complex script which looks similar to this command:
find /home/user/videos/*.avi -mtime +0 -exec mv -f {} "/home/nb/videos/1 day old" \;
And then I run the same command, but this time, from the "1 day old" folder into a "2 days old" folder. And some more commands keep repeating all the way up to 7 days old! So each day, files from the previous "X days old" folder move into the next day up's folder.
I'm basically trying to organise files automatically, running in cron, to move files older then X days into the correct folder. It's inefficient, but I do need this to happen. Is there any easier, more efficient way?
Once it gets to the 7 days old folder, I have the final command which removes files older than 7 days from that last folder.
I use (for a similar situation) a non-standard way:
logrotate
.This will back up all videos in
/home/user/videos
to the/home/nb/videos/backup/videos.tar
file (daily), and then automatically move the oldtar
files to...1.tar
,...2.tar
etc. Backups older than 7 days will be deleted.I included
mv /home/user/videos/*.avi /var/tmp
to keep a copy of videos in case anything goes wrong.To activate this logrotate configuration put a similar file to this to the
/etc/logrotate.d
directory:For more information see
man logrotate
.