LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Archive files (https://www.linuxquestions.org/questions/linux-newbie-8/archive-files-709564/)

ust 03-06-2009 02:52 AM

Archive files
 
In my system , there are many files , I would like to tar zip files which older than 100 days , I use the below script

find . -mtime +100 -exec tar -zcvf my_file {} \;

after run the script , the file "my_file" is created , but I found that this file (my_file) only contains one of these files ( the file older than 100 days ) , but there should have over 1000 files , can advise how to tar zip all files ?


thx

colucix 03-06-2009 02:57 AM

Code:

find . -mtime +100 -print0 | xargs -0 tar --no-recursion -zcvpf archive.tar.gz
Happy Birthday! :)

ust 03-06-2009 03:49 AM

Quote:

Originally Posted by colucix (Post 3466634)
Code:

find . -mtime +100 -print0 | xargs -0 tar --no-recursion -zcvpf archive.tar.gz
Happy Birthday! :)

thx reply ,

it works fine , I think --no-recursion is the cue , but I tried the below script is not work, can advise what is wrong in my script ? thx

find . -mtime +1000 -exec tar --no-recursion -zcvf /tmp/archive.tar.gz {} \;

colucix 03-06-2009 05:13 AM

I think it is the way -exec and xargs execute their task. -exec execute the specified command for each file, resulting in multiple tar commands. This brings to overwriting the existing archive every time and leaves the last processed file alone into the archive. xargs receive the entire list of files and process all of them as arguments of the tar command: in this case tar is executed only once and the whole list of files goes into the archive.


All times are GMT -5. The time now is 03:21 AM.