Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-30-2006, 07:59 PM   #1
Registered: Dec 2005
Distribution: slackware-current
Posts: 86

Rep: Reputation: 16
find and tar

how do i use find with tar? command below tars the files twice. i tried with tar -rvf and same results.

find /etc -type f -name "*.bak" | xargs tar -cvf test.tar
Old 10-30-2006, 08:08 PM   #2
Registered: Dec 2004
Location: Benicia, CA
Distribution: Fedora 6,5,4 Mandrake 10.1
Posts: 46

Rep: Reputation: 15
what about locate test.tar first run updatedb if you never have then locate xxxx being whatever your looking for
Old 10-30-2006, 08:48 PM   #3
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

Try the following:
find /etc -type f -name '*.bak' -print0 | tar cvf test.tar --null -T -

Last edited by ilikejam; 10-30-2006 at 08:50 PM.
Old 10-31-2006, 12:46 AM   #4
Registered: Jul 2004
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
My way:
find /etc -type f -name '*.bak' -exec tar cvf test.tar {} \;
-exec is an option of find
man find
Old 10-31-2006, 01:49 AM   #5
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
@ebasi: tar's "c" option creates a new tar archive. Since find's -exec is executed for each file found, I suspect you'll be (re)creating the same test.tar file many times.

A not-so-nice work-around would be:
tar cvf test.tar dummy_file #creates tar
find /etc -type f -name '*.bak' -exec tar rvf test.tar {} \; #appends all *.bak files to tar
tar --delete -f test.tar dummy_file #removes dummy file again
Note that this work-around won't work for tar archives on tape.

slackamp, you could also try something like:
find /etc -type f -name '*.bak' > files2tar
tar --files-from=files2tar -v -f test.tar
rm files2tar


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 10:55 AM
Where I find driver slmodem-2.9.6.tar.gz ? caneca Linux - Newbie 2 10-25-2005 08:25 AM
where to find a tar-file in a rpm sneezesnoeze Linux - Newbie 1 04-06-2004 11:18 AM
Installed RPM/tar file, cant find out how to run it Craneology Linux - Software 4 03-01-2003 08:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:29 PM.

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