Download your favorite Linux distribution at LQ ISO.
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 02-13-2008, 11:09 AM   #1
Registered: Aug 2007
Posts: 35

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?

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

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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.
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
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389

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
Registered: Aug 2007
Posts: 35

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


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 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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:56 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