LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-29-2021, 11:35 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Talking Is this possible? Create a tar.gz of a directory and place it in a different directory without all of the directories nested in the path?


Lemme explain. I wanna back up webroot located at /var/www/html/webroot by creating a file called webroot.tar.gz but I wanna place it in /var/www/html/archive, in the archive itself I only want to see the webroot directory, and it's files contained with in. I do not want to open the archive and see var, then www, then html, then webroot. I have a feeling I need to be using the -C option but I can't for the life of me figure out how.

Any tips? I am hoping to do this in a single command.

Update: I figured it out! Thanks for reading anyhow.

Code:
tar -czf /var/www/html/archive/webroot.tar.gz -C /var/www/html/ webroot

Last edited by wh33t; 10-29-2021 at 11:40 PM.
 
Old 10-30-2021, 01:49 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,780

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
-C changes the start directory.
You can achieve the same with
Code:
( cd /var/www/html && tar -czf /var/www/html/archive/webroot.tar.gz webroot )
 
1 members found this post helpful.
Old 10-30-2021, 03:50 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,789

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
you must not put the tar created into the source directory tree (conflict between -C <dir> and -f <file>). Or at least do it in two steps: first create that tar somewhere outside and finally move it to the final location. (post #2 is ok, because webroot is packed into archive).
 
1 members found this post helpful.
Old 10-30-2021, 09:46 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,780

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Good point in principle,
but here the webroot aka /var/www/html/webroot is outside.
 
1 members found this post helpful.
Old 10-30-2021, 10:03 AM   #5
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by MadeInGermany View Post
-C changes the start directory.
You can achieve the same with
Code:
( cd /var/www/html && tar -czf /var/www/html/archive/webroot.tar.gz webroot )
I should have mentioned this needs to fire from exec() in php land. I wasn't sure if or how I could toss multiple commands into a single function call, and if I were to do it in two, I wasn't sure how the system would be aware or keep track of the fact that I am now in a different directory.

Thanks for the explanations all!

Last edited by wh33t; 10-30-2021 at 10:06 AM.
 
  


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
[SOLVED] script to create tar list and then un-tar using wildcards for lots of directories green99 Linux - General 2 06-26-2012 04:40 AM
How to store files/directories in different different directories!! anishkumarv Linux - Newbie 7 03-23-2011 05:26 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
How do I un tar a .tar, .tar.z, .tar.gz file vofkid Linux - Newbie 4 03-15-2002 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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