LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 05-09-2012, 08:24 PM   #1
kevinandrews
LQ Newbie
 
Registered: Mar 2010
Location: Farmington Hills, MI
Distribution: Ubuntu 11.10
Posts: 5

Rep: Reputation: 0
having issue with tar and find programs under Ubuntu 11.10


Hello,

Basically what I'm trying to do is tar up a bunch of files on my system. I want to use tar to create the archive and use find to get all of the files to be archived. I want all of the logfileson my system in this archive. Here is what happened, and it makes no sense. Wht's going on? What am I doing wrong? Thanks for your help!

root@techwizard:~#
tar -cf logs2012-05-09.tar > find / -name '*.log'
tar: invalid option -- 'e'
Try `tar --help' or `tar --usage' for more information.
root@techwizard:~#
 
Old 05-10-2012, 05:01 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
you can use the -exec option of find.
Code:
fukawi1 /var/log # find . -iname '*.log' -exec tar -czvf /tmp/tmp.tar.gz '{}' \;
./gdm/:0.log
./gdm/:0-greeter.log
./gdm/:0-slave.log
./Xorg.9.log
./dracut.log
./yum.log
./prelink/prelink.log
./setroubleshoot/setroubleshootd.log
./pm-powersave.log
./wpa_supplicant.log
./audit/audit.log
./boot.log
./iscsiuio.log
./Xorg.0.log
./anaconda/anaconda.program.log
./anaconda/anaconda.log
./anaconda/anaconda.storage.log
./anaconda/anaconda.ifcfg.log
./jockey.log
fukawi1 /var/log #
This will execute the tar command using the found results in place of the {}'s the 's are to correctly handle files with spaces/etc, and the \; signifies the end of the command to be executed.
 
Old 05-10-2012, 07:27 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,774

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by fukawi1 View Post
you can use the -exec option of find.
Code:
fukawi1 /var/log # find . -iname '*.log' -exec tar -czvf /tmp/tmp.tar.gz '{}' \;
./gdm/:0.log
./gdm/:0-greeter.log
...
./anaconda/anaconda.ifcfg.log
./jockey.log
fukawi1 /var/log #
That will execute the tar command using the found results in place of the {}'s the 's are to correctly handle files with spaces/etc, and the \; signifies the end of the command to be executed.
That command will execute tar separately and create the archive anew for each file found. You will end up with /tmp/tmp.tar.gz containing only the last file found, in this case "./jockey.log".
 
1 members found this post helpful.
Old 05-10-2012, 07:45 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,672

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
rknichols is correct.

You need to use xargs and these links might help.
http://www.linuxquestions.org/questi...pected-856455/
http://linuxgazette.net/111/tag/4.html
 
1 members found this post helpful.
Old 05-10-2012, 11:22 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,774

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Using xargs can silently fail too if the argument list becomes longer than what can be passed in a single exec() call. To be ironclad, you need to pass all the names null-terminated to a single invocation of tar:
Code:
find / -name '*.log' -print0 | tar -cf logs2012-05-09.tar --null --files-from -
AFAIK, that should be able to handle anything except permissions problems or running out of space for the archive, though it might be worthwhile to prune various pseudo-filesystems like /proc and /sys from the find search.
 
1 members found this post helpful.
Old 05-11-2012, 03:42 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Good catch, in my defense, that was a cut and paste error there of a command I tried erroneously working on reaching the below example, which is what should have been pasted. Apologies for the confusion..
Code:
fukawi1 /var/log # find . -iname '*.log' -exec tar -rvf /tmp/test.tar '{}' \;
./gdm/:0.log
./gdm/:0-greeter.log
./gdm/:0-slave.log
./Xorg.9.log
./dracut.log
./yum.log
./prelink/prelink.log
./setroubleshoot/setroubleshootd.log
./pm-powersave.log
./wpa_supplicant.log
./audit/audit.log
./boot.log
./iscsiuio.log
./Xorg.0.log
./anaconda/anaconda.program.log
./anaconda/anaconda.log
./anaconda/anaconda.storage.log
./anaconda/anaconda.ifcfg.log
./jockey.log
fukawi1 /var/log # tar -tf /tmp/test.tar
./jockey.log
./gdm/:0.log
./gdm/:0-greeter.log
./gdm/:0-slave.log
./Xorg.9.log
./dracut.log
./yum.log
./prelink/prelink.log
./setroubleshoot/setroubleshootd.log
./pm-powersave.log
./wpa_supplicant.log
./audit/audit.log
./boot.log
./iscsiuio.log
./Xorg.0.log
./anaconda/anaconda.program.log
./anaconda/anaconda.log
./anaconda/anaconda.storage.log
./anaconda/anaconda.ifcfg.log
./jockey.log
fukawi1 /var/log #
That being said, I can see rknichols solution covers more bases as far as things going wrong are concerned.

Learn something new every day, as they say.
 
  


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
Installing Programs from Tar,gz RedFedora Linux - Newbie 8 01-15-2012 08:51 PM
[SOLVED] Tar returns with error in Ubuntu 11.10 (tar version 1.22) call_krushna Linux - Server 3 01-06-2012 02:03 AM
Script to find tar archives, read tar file contents, output content to an index file. bluesword1969 Linux - General 4 02-07-2011 12:15 PM
need some help with muli-volume tar (ubuntu, bash, gnu tar) MattCarp Linux - General 4 06-05-2006 08:15 AM
.tar.gz to .deb? Any Programs? badgerbox76 Linux - Software 4 02-19-2006 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 06:48 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
Open Source Consulting | Domain Registration