UNIX Script Help

I have a bunch of .tar.gz files. here is an example.

batch_files_04012016.tar.gz
batch_files_04022016.tar.gz
batch_files_04013016.tar.gz
....etc

I have the files for 3 years.
My job is I have to untar and unzip the last 3 years files and choose the right file from untared files and copy into the different folder
with out manual process. Is there anyway we can do this with small manual work.

If you know "the right file" name, you can extract exactly and only that one right into the "different folder"

I guess the batch_files_04013016.tar.gz you mentioned was doing time travel, coming right to the future :wink:

In any case, there is more one needs to know for solving this one:

  • I guess you deduce the "age" of the file from the time string in its filename, k.e. 04012016, and not the last modification time (or last access time) of the file, right? If you can use the modification time, it's easier to do, but if someone explicitly touches an old file, this file will stay for longer (this might be seen as a feature, because you can exclude important files from deletion by touching them).

  • Should the files being left, cover *exactly* the last 3 years (3 times 356 days) from the time of deletion, or should it be ensured that they cover the last previous full years? For instance, if you delete in February 2017, is it necessary that the file from January 2014 is also gone, or is it OK to just erase everything up to 2016?