1837836 Members
2519 Online
110121 Solutions
New Discussion

help with tar please

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

help with tar please

hello,

I have a directory caled /xx/xxx/prod. I would like to tar everything in teh prod directory to a directory called /tmp. How would I do this with the tar -cvf command so that my tar file is now located in /tmp directory. Any help will be greatly appreciated.
7 REPLIES 7
Santosh Nair_1
Honored Contributor
Solution

Re: help with tar please

If you're just trying to create a tar archive in the /tmp directory, do the following:

cd /xx/xxx
tar cvf /tmp/prod.tar prod

this will create a tar file called prod.tar in /tmp with the contents of ther prod directory in /xx/xxx

-Santosh
Life is what's happening while you're busy making other plans
John Poff
Honored Contributor

Re: help with tar please

Hello,

Try:

tar -cvf /tmp/my.tar /xx/xxx/prod
Patrick Wallek
Honored Contributor

Re: help with tar please

# cd /xxx/xxx/
# tar -cvf /tmp/prod.tar ./prod

or

# cd /xxx/xxx/prod
# tar -cvf /tmp/prod.tar .
(notice that there is a space between /tmp/prod.tar and the dot)
Ragni Singh
Super Advisor

Re: help with tar please

and then how would I untar this to the /prod directory. I would like to put all the contents in the /xx/xxx/prod directory. Thanks for the help
John Poff
Honored Contributor

Re: help with tar please

Try:

cd /prod
tar -xvf /tmp/my.tar

If you used my example above it would put the full path on each file which probably isn't what you want. Better to do it like the other replies and 'cd' to the directory first.

JP
Patrick Wallek
Honored Contributor

Re: help with tar please

If you created the tar file with the following:
# cd /xxx/xxx
# tar -cvf /tmp/prod.tar ./prod

Then untar into /prod directory by:
# cd /
# tar -xvf /tmp/prod.tar


If you created the tar file with the following:
#cd /xxx/xxx/prod
tar -cvf /tmp/prod.tar .

Then untar into /prod directory by:
# cd /prod
# tar -xvf /tmp/prod.tar

Arthur Bazan
New Member

Re: help with tar please

This is how I move files using tar:
cd /xx/xxx/prod
tar cf - . |(cd /tmp; tar xpf -)
This command will tar up the files, and in the sub-shell (inside parens) will move to the new directory and untar the files.

If this is done as "root" it will save all the permission and date/timestamp.

art