LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2009, 02:52 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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
 
Old 03-06-2009, 02:57 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Code:
find . -mtime +100 -print0 | xargs -0 tar --no-recursion -zcvpf archive.tar.gz
Happy Birthday!
 
Old 03-06-2009, 03:49 AM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
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 {} \;
 
Old 03-06-2009, 05:13 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy archive files in Linux? pmorg Linux - General 3 10-24-2007 12:55 PM
Extracting files from .bin archive Sir Loin Linux - Software 5 03-25-2007 08:12 PM
Restrict exe files inside an archive files in samba paulreynand Linux - Networking 2 02-02-2006 04:07 AM
What Are archive.zip files? kajensen Linux - General 1 09-21-2003 04:00 AM
Moving files into an archive gkep Linux - Newbie 2 07-27-2003 09:42 PM


All times are GMT -5. The time now is 09:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration