Operating System - HP-UX
1833777 Members
2246 Online
110063 Solutions
New Discussion

Re: Create a tar ball in a different directory than what I want to tar

 
SOLVED
Go to solution
KPS
Super Advisor

Create a tar ball in a different directory than what I want to tar

I'm trying to do a tarball of a directory and all of it's sub-directories underneath it. I'm trying to create this in a different directory, than what I'm tarring up, due to space constraints. What I'm looking for is how do i use the following command in the context of putting the actual tar file in a different directory?

1.) cd /usr/local/job (I want to tar up the contents of this directory)

2.) tar cvf ??????? (What else do I need here)
8 REPLIES 8
S.K. Chan
Honored Contributor
Solution

Re: Create a tar ball in a different directory than what I want to tar

# cd /usr/local/job
# tar cvf /tmp/myfile.tar .
That should tar up everything under /usr/local/job and create the tar file "myfile.tar" in /tmp.
Jeff Schussele
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar

Hi Ken,

Use it as follows:

tar cvf /path/to/file.tar /usr/local/job

With this command you can be anywhere, but be advised it will ONLY extract to /usr/local/job

Else you can do this relative as follows:

cd /usr/local
tar cvf /path/to/file.tar ./job

This will create a tarball that looks like
./job/xxxxxx that can be extracted into anywhere

OR even
cd /usr/local/job
tar cvf /path/to/file.tar .

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
John Bolene
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar

depends on if you want absolute or relative
relative
cd /usr/local
tar -cf /tmp/file.tar job

absolute
tar -cf /tmp/file.tar /usr/local/job
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Sean OB_1
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar

1. cd /usr/local/job
2. tar -cvf /tmp/newtarfile.tar *

the -f tells it what file to write to.
Darrell Allen
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar

Hi Ken,

cd /usr/local/job
tar cvf /different_dir/tarfile_name .

This will create your tarball in /different_dir/tarfile_name. the " ." at the end of the tar command says to select the current directory. All files in /usr/local/job and it's sub-directories will be included.

This will also create the tarball with relative pathnames. That's always a good idea because you can easily extract it to a new location.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
MANOJ SRIVASTAVA
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar

just do a tar cvf /dev/rmt/0m * this willt ar evderythin under /usr/local/job witht he absolute path not including /usr/local/job but everything under it.



Manoj Srivastava
Jordan Bean
Honored Contributor

Re: Create a tar ball in a different directory than what I want to tar


Of if you want to be in the directory where the tarball is to be created, you could do it this way:

cd /tmp; tar cf job.tar -C /usr/local/job .

or

cd /tmp; tar cf job.tar -C /usr/local job

or add a little compression:

cd /tmp; tar cf - -C /usr/local job | gzip -c > job.tgz

You get the idea.

Moser Hermann
New Member

Re: Create a tar ball in a different directory than what I want to tar

I do you this syntax:

cd /dir_old
tar -cf - . | (cd /dir_new; tar -xf -)

Moser Hermann