LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   extract tar.gz to absolute path (https://www.linuxquestions.org/questions/linux-newbie-8/extract-tar-gz-to-absolute-path-4175635688/)

unclejed613 08-05-2018 12:33 AM

extract tar.gz to absolute path
 
i'm helping somebody build a web page, and want to have a tar.gz archive of the whole file tree extract into /var/www/html/weblog. the file tree has been archived by adding /home/user/var to the archive, so that the top folder in the archive is /var. how do i insure the file tree in the archive drops into /var on the web server when it's extracted? the actual file tree inside the archive is /var/www/html/weblog with several subdirectories included below weblog. i see plenty of people ask online how to extract into a relative path, because the search terms "extract tar.gz to absolute path" brings up scads of questions on how to avoid extraction to absolute paths.

abga 08-05-2018 04:25 AM

Use the -C switch when extracting always pointing to the top of the tree from your archive.
https://superuser.com/questions/3638...oes-tar-c-mean
Code:

cd /home/user/
tar -czpf /yourpath/weblog.tar.gz var/www/html/weblog/
tar -xzpf /yourpath/weblog.tar.gz -C /home/user/
#or
cd /
tar -czpf /yourpath/weblog.tar.gz home/user/var/www/html/weblog/
tar -xzpf /yourpath/weblog.tar.gz -C /


jostber 08-05-2018 10:59 AM

https://www.linuxquestions.org/quest...th-4175421197/


All times are GMT -5. The time now is 05:26 AM.