-   Linux - Newbie (
-   -   Tar files in a dir modified before 7 days in a shell script (

jayachristina 04-29-2004 03:01 AM

Tar files in a dir modified before 7 days in a shell script
How could I tar the files (*.csv files) in a directory which are 7 days old?
I need to do this for archiving purposes.
Can you please help out?


hw-tph 04-29-2004 03:37 AM


find . -ctime -7 -type f -name "*.csv"
This will list the files with .csv extension that have been created during the last seven days.

Edited addition: If you want to use the above to tar them up you could use something like this:

tar cfz `date +%Y-week%V`.tar.gz `find . -ctime -7 -type f -name "*.csv"`
(note the backticks for command substitution)This will create a compressed tar file with the csv files created during the last 7 days, and the filename will be YYYY-weekN.tar.gz (currently it would be 2004-week18.tar.gz). Try man date for more options on formatting date output.


jayachristina 04-29-2004 04:14 AM

Thanks Håkan.
This is exactly what I wanted
But in 'tar cfz ', the z seems to be an invalid option!
tar: z: unknown option
But I can always compress this file again, so that would not be a problem
Thanks again

Arkane 05-13-2004 06:37 AM


Is it possible to use tar to extract a list of files stored in a file or stdinput?

I 've got a dir with lots of tar files.. and want to choose some with grep.



Arkane 05-14-2004 02:49 AM

Hi again and sorry for answering my own question... i 've found a solution this morning...
Since i didn't get it with tar -T i searched a little around and tried xargs

ls |grep "tar.gz" |xargs -n1 tar -xzf

and my problem was gone :)

I love the pipe!

All times are GMT -5. The time now is 03:07 PM.