Computing HowTo Linux

How to archive folders older than a certain date in Linux / Ubuntu

Using the GUI this task is trivial (Sort by list view, click on the Date heading to order by date, select the relevant folders then right click and Compress.)

Using the command line to achieve the same results is a trifle harder. Here’s the command line I came up with:

tar zcvf ArchiveName.tar.gz `find * -maxdepth 0 -mtime +893`

The find command in the gets executed first and returns the folders and files in the CURRENT directory that haven’t been modified since the number of days specified by the number in the find command.

Tar then does it’s usual job and compresses it.

If you’re wanting to remove directories using a similar command just substitute in the rm command instead of the tar command.

To find the number of days to a date in the past I used this website here but I’m sure there’s something you can do with the date command that will give you a similar output!