LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 02-13-2008, 11:09 AM   #1
tejama
Member
 
Registered: Aug 2007
Posts: 37

Rep: Reputation: 15
Easy scripting question - tar


I'm trying to write a script to tar a list of files in a directory. The line I'm using is:

tar -cvf /home/ma1234/blah.tar /home/ma1234/test/*.*

The issue I'm having is that this line does create the archive, but when I extract it, it is the full directory structure (ie: the home directory is listed, the I can drill down to the ma1234, then finally to the test directory where all the files are located).

How can I modify this script to include only the files and not the directory structure?

Thanks.
 
Old 02-13-2008, 11:22 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Code:
tar -cvf /home/ma1234/blah.tar /home/ma1234/test/*.*
To have tar archive the contents of /test, and leave the archive in /home/ma1234 with the filename blah.tar, your script has to cd to /home/ma1234 before making the archive.
Code:
cd /home/ma1234
tar cvf blah.tar test/*

Last edited by bigrigdriver; 02-13-2008 at 11:29 AM.
 
Old 02-13-2008, 11:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Or use the tar options:

tar cfC /home/ma1234/blah.tar /home/ma1234 .

The above command will create a tar file called blah.tar in the directory called /home/ma1234. Before tar starts tarring it first cd's to /home/ma1234 (with use of the C option) and tar's all from there (the . [dot]).
 
Old 02-13-2008, 12:08 PM   #4
tejama
Member
 
Registered: Aug 2007
Posts: 37

Original Poster
Rep: Reputation: 15
Thanks guys. I tried both solutions and both worked perfectly.
 
  


Reply



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
EASY scripting question - trying to figure out a test statement Elendrael Linux - Newbie 1 09-16-2007 07:52 PM
LXer: Shell Scripting, oooh...its easy LXer Syndicated Linux News 0 11-27-2006 09:54 AM
Another easy Bourne Shell Scripting question WinterSt Programming 7 09-02-2004 07:41 PM
Scripting problems - I'm sure this should be easy! webamoeba Linux - Newbie 6 02-03-2004 09:58 AM
easy tar.gz question moose1618 Linux - Software 11 02-21-2002 11:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:06 AM.

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