How do you extract a single folder from a large tar.gz archive?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
97
down vote

favorite
29












I am using this command on a 5GB archive



tar -zxvf archive.tar.gz /folder/in/archive


is this the correct way to do this? It seems to be taking forever with no command line output...










share|improve this question























  • Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
    – Kevin
    Mar 29 '12 at 14:20











  • Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
    – Garrett Hall
    Mar 29 '12 at 14:43






  • 3




    On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
    – Gilles
    Mar 29 '12 at 22:35










  • The important part is also no trailing slash. Using folder/folder2/ won't work.
    – Marki555
    Mar 20 '17 at 9:49














up vote
97
down vote

favorite
29












I am using this command on a 5GB archive



tar -zxvf archive.tar.gz /folder/in/archive


is this the correct way to do this? It seems to be taking forever with no command line output...










share|improve this question























  • Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
    – Kevin
    Mar 29 '12 at 14:20











  • Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
    – Garrett Hall
    Mar 29 '12 at 14:43






  • 3




    On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
    – Gilles
    Mar 29 '12 at 22:35










  • The important part is also no trailing slash. Using folder/folder2/ won't work.
    – Marki555
    Mar 20 '17 at 9:49












up vote
97
down vote

favorite
29









up vote
97
down vote

favorite
29






29





I am using this command on a 5GB archive



tar -zxvf archive.tar.gz /folder/in/archive


is this the correct way to do this? It seems to be taking forever with no command line output...










share|improve this question















I am using this command on a 5GB archive



tar -zxvf archive.tar.gz /folder/in/archive


is this the correct way to do this? It seems to be taking forever with no command line output...







shell tar gzip






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 '17 at 19:14









don_crissti

47.4k15126155




47.4k15126155










asked Mar 29 '12 at 14:00









Garrett Hall

1,28631311




1,28631311











  • Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
    – Kevin
    Mar 29 '12 at 14:20











  • Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
    – Garrett Hall
    Mar 29 '12 at 14:43






  • 3




    On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
    – Gilles
    Mar 29 '12 at 22:35










  • The important part is also no trailing slash. Using folder/folder2/ won't work.
    – Marki555
    Mar 20 '17 at 9:49
















  • Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
    – Kevin
    Mar 29 '12 at 14:20











  • Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
    – Garrett Hall
    Mar 29 '12 at 14:43






  • 3




    On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
    – Gilles
    Mar 29 '12 at 22:35










  • The important part is also no trailing slash. Using folder/folder2/ won't work.
    – Marki555
    Mar 20 '17 at 9:49















Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
– Kevin
Mar 29 '12 at 14:20





Did you use an absolute or relative path? Should be relative, other than that it looks right. How long did you let it run, and how good is your system? It will take at least several minutes on a fast machine. Potentially an hour or more? I'm running a test now.
– Kevin
Mar 29 '12 at 14:20













Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
– Garrett Hall
Mar 29 '12 at 14:43




Yes, it completed after ~1hr, but the absolute path was wrong, you were correct.
– Garrett Hall
Mar 29 '12 at 14:43




3




3




On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
– Gilles
Mar 29 '12 at 22:35




On Linux, you can watch how far into the archive tar is with cat /proc/$(pidof tar)/fdinfo/0 (adapt the command if you have more than one tar process running).
– Gilles
Mar 29 '12 at 22:35












The important part is also no trailing slash. Using folder/folder2/ won't work.
– Marki555
Mar 20 '17 at 9:49




The important part is also no trailing slash. Using folder/folder2/ won't work.
– Marki555
Mar 20 '17 at 9:49










1 Answer
1






active

oldest

votes

















up vote
110
down vote



accepted










tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:



tar -cf foo.tar /home/foo
tar: Removing leading `/' from member names


If you need to extract a particular folder, have a look at what's in the tar file:



tar -tvf foo.tar


And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:



tar -xvf foo.tar home/foo/bar # Note: no leading slash


So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:



tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option


There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.



Note: if you use the -P option, tar will archive absolute paths. So it always pays to check the contents of big archives before extracting.






share|improve this answer


















  • 22




    --strip-components=N may be useful to some here.
    – A-B-B
    Jul 18 '14 at 21:57






  • 2




    in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
    – santiago arizti
    Nov 30 '16 at 3:32






  • 1




    And about .gz ?
    – Peter Krauss
    Aug 4 '17 at 23:04










  • @PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
    – Alexios
    Aug 5 '17 at 6:40










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35311%2fhow-do-you-extract-a-single-folder-from-a-large-tar-gz-archive%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
110
down vote



accepted










tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:



tar -cf foo.tar /home/foo
tar: Removing leading `/' from member names


If you need to extract a particular folder, have a look at what's in the tar file:



tar -tvf foo.tar


And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:



tar -xvf foo.tar home/foo/bar # Note: no leading slash


So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:



tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option


There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.



Note: if you use the -P option, tar will archive absolute paths. So it always pays to check the contents of big archives before extracting.






share|improve this answer


















  • 22




    --strip-components=N may be useful to some here.
    – A-B-B
    Jul 18 '14 at 21:57






  • 2




    in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
    – santiago arizti
    Nov 30 '16 at 3:32






  • 1




    And about .gz ?
    – Peter Krauss
    Aug 4 '17 at 23:04










  • @PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
    – Alexios
    Aug 5 '17 at 6:40














up vote
110
down vote



accepted










tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:



tar -cf foo.tar /home/foo
tar: Removing leading `/' from member names


If you need to extract a particular folder, have a look at what's in the tar file:



tar -tvf foo.tar


And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:



tar -xvf foo.tar home/foo/bar # Note: no leading slash


So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:



tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option


There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.



Note: if you use the -P option, tar will archive absolute paths. So it always pays to check the contents of big archives before extracting.






share|improve this answer


















  • 22




    --strip-components=N may be useful to some here.
    – A-B-B
    Jul 18 '14 at 21:57






  • 2




    in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
    – santiago arizti
    Nov 30 '16 at 3:32






  • 1




    And about .gz ?
    – Peter Krauss
    Aug 4 '17 at 23:04










  • @PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
    – Alexios
    Aug 5 '17 at 6:40












up vote
110
down vote



accepted







up vote
110
down vote



accepted






tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:



tar -cf foo.tar /home/foo
tar: Removing leading `/' from member names


If you need to extract a particular folder, have a look at what's in the tar file:



tar -tvf foo.tar


And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:



tar -xvf foo.tar home/foo/bar # Note: no leading slash


So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:



tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option


There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.



Note: if you use the -P option, tar will archive absolute paths. So it always pays to check the contents of big archives before extracting.






share|improve this answer














tar stores relative paths by default. GNU tar even says so if you try to store an absolute path:



tar -cf foo.tar /home/foo
tar: Removing leading `/' from member names


If you need to extract a particular folder, have a look at what's in the tar file:



tar -tvf foo.tar


And note the exact filename. In the case of my foo.tar file, I could extract /home/foo/bar by saying:



tar -xvf foo.tar home/foo/bar # Note: no leading slash


So no, the way you posted isn't (necessarily) the correct way to do it. You have to leave out the leading slash. If you want to simulate absolute paths, do cd / first and make sure you're the superuser. Also, this does the same:



tar -C / -xvf foo.tar home/foo/bar # -C is the ‘change directory’ option


There are very obvious, good reasons why tar converts paths to relative ones. One is the ability to restore an archive in places other than its original source. The other is security. You could extract an archive, expect its files to appear in your current working directory, and instead overwrite system files (or your own work) elsewhere by mistake.



Note: if you use the -P option, tar will archive absolute paths. So it always pays to check the contents of big archives before extracting.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 22 '14 at 12:25

























answered Mar 29 '12 at 14:35









Alexios

13.8k14665




13.8k14665







  • 22




    --strip-components=N may be useful to some here.
    – A-B-B
    Jul 18 '14 at 21:57






  • 2




    in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
    – santiago arizti
    Nov 30 '16 at 3:32






  • 1




    And about .gz ?
    – Peter Krauss
    Aug 4 '17 at 23:04










  • @PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
    – Alexios
    Aug 5 '17 at 6:40












  • 22




    --strip-components=N may be useful to some here.
    – A-B-B
    Jul 18 '14 at 21:57






  • 2




    in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
    – santiago arizti
    Nov 30 '16 at 3:32






  • 1




    And about .gz ?
    – Peter Krauss
    Aug 4 '17 at 23:04










  • @PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
    – Alexios
    Aug 5 '17 at 6:40







22




22




--strip-components=N may be useful to some here.
– A-B-B
Jul 18 '14 at 21:57




--strip-components=N may be useful to some here.
– A-B-B
Jul 18 '14 at 21:57




2




2




in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
– santiago arizti
Nov 30 '16 at 3:32




in my case it was necessary to write ./foldername/ instead of foldername, I guess that it was because when I created the tar I created it with tar -cvf santi.tar ./* and when I "listed" the tar this is what it said drwxr-xr-x santi/santi 0 2016-04-11 09:42 ./foldername/
– santiago arizti
Nov 30 '16 at 3:32




1




1




And about .gz ?
– Peter Krauss
Aug 4 '17 at 23:04




And about .gz ?
– Peter Krauss
Aug 4 '17 at 23:04












@PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
– Alexios
Aug 5 '17 at 6:40




@PeterKrauss change -xvf to -xzvf (adding the -z option) and obviously foo.tar to foo.tar.gz or whatever your archive is named. The same holds for -j (bz2) and on some recent versions, -J (xz). Otherwise, a pipeline like zcat foo.tar.gz | tar -xvf - … also works.
– Alexios
Aug 5 '17 at 6:40

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35311%2fhow-do-you-extract-a-single-folder-from-a-large-tar-gz-archive%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay