LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-07-2014, 12:09 AM   #1
hakkimmiet
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Rep: Reputation: Disabled
How to create tar.gz in different directory..


Hi all,

I need to create a tar.gz directory in different location. I am using the following command.

tar -czvf file.tar.gz file

can any one please help me to create tar.gz in different directory.


Thanks
 
Old 08-07-2014, 12:12 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by hakkimmiet View Post
Hi all,

I need to create a tar.gz directory in different location. I am using the following command.

tar -czvf file.tar.gz file

can any one please help me to create tar.gz in different directory.


Thanks
Code:
tar -czvf /path-to/other/directory/file.tar.gz file
 
Old 08-07-2014, 01:24 AM   #3
hakkimmiet
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi Astrogeek,

Thanks for your reply.

I have tried with your command but when i am tar a directory with full path, its get compressed as full path.

when untar the same directory, its get extracted as full path location.


Ex:-


Source File location:-
*********************

/tmp/test/backup/


Backup Directory:-
*****************

/root/Desktop/backup.tar.gz


tar -czvf /root/Desktop/backup.tar.gz /tmp/test/backup



After that, when i am untar the same file its get extracted as /root/Desktop/backup/ directory.

But i need to extract as backup/ directory alone.


Issue is when i am creating tar with full path, its get compressed as full path .tar.gz file. I dont want to tar as full path.

Need to filter that full path when creating .tar.gz file.

Please help me on this...


Thanks,
 
Old 08-07-2014, 01:47 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by hakkimmiet View Post
Hi Astrogeek,

Thanks for your reply.

I have tried with your command but when i am tar a directory with full path, its get compressed as full path.

when untar the same directory, its get extracted as full path location.


Ex:-


Source File location:-
*********************

/tmp/test/backup/


Backup Directory:-
*****************

/root/Desktop/backup.tar.gz


tar -czvf /root/Desktop/backup.tar.gz /tmp/test/backup



After that, when i am untar the same file its get extracted as /root/Desktop/backup/ directory.

But i need to extract as backup/ directory alone.


Issue is when i am creating tar with full path, its get compressed as full path .tar.gz file. I dont want to tar as full path.

Need to filter that full path when creating .tar.gz file.

Please help me on this...


Thanks,
Actually, no. The path to the backup location (destination) is not stored in the tar file at all.

But the path to the source files is stored in the tar file by default relative to where the tar command was issued from unless absolute path is given.

In your original question you did not say anything about what part of the path you want to preserve or where you want to untar it, so maybe you could be a little more complete in your problem description.

You might also want to see man tar, -C and -P options in particular.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Tar of a directory present in another server Vi_rod Linux - Newbie 1 03-21-2012 09:21 AM
Using TAR to create backup of files created today in data directory Vi_rod Linux - Newbie 3 12-23-2011 12:00 PM
How can i create .tar.gz,.tar.bz2,.zip file and upload with filezilla=> uncompress? cola Linux - General 1 09-14-2011 01:32 PM
How to create .diff.gz/.dsc/.orig.tar.gz from a downloaded tar.gz application? frenchn00b Linux - General 4 05-18-2008 09:09 AM
Unable to create a tar file from spanning a directory tree? R00ts Linux - General 2 11-01-2006 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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