LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 12:09 PM   #1
tejama
Member
 
Registered: Aug 2007
Posts: 34

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, 12:22 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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 12:29 PM.
 
Old 02-13-2008, 12:34 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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, 01:08 PM   #4
tejama
Member
 
Registered: Aug 2007
Posts: 34

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


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


All times are GMT -5. The time now is 12:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration