Create tar file that extracts only the files and doesn't create folder during extract

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











up vote
0
down vote

favorite












I have a folder with files which I want to zip into a tar.gz file. I am using the following command:



tar -czvf filename.tar.gz foldername


Sure enough this creates the file filename.tar.gz. However, when I unzip the tar file, by default it creates a folder filename and places all the files into the folder.



Can I avoid this folder creation when I create the tar file itself. I tried the following command but it doesn't work.



tar -czv filename.tar.gz foldername


I am using Ubuntu 14.04.



My current directory structure is as follows:



~/Test/foldername


The directory foldername has all the files that I want to zip. My codes are as follows:



cd Test
tar czvf filename.tar foldername/*






share|improve this question






















  • You can always cd before zipping
    – Weijun Zhou
    Jan 15 at 7:12














up vote
0
down vote

favorite












I have a folder with files which I want to zip into a tar.gz file. I am using the following command:



tar -czvf filename.tar.gz foldername


Sure enough this creates the file filename.tar.gz. However, when I unzip the tar file, by default it creates a folder filename and places all the files into the folder.



Can I avoid this folder creation when I create the tar file itself. I tried the following command but it doesn't work.



tar -czv filename.tar.gz foldername


I am using Ubuntu 14.04.



My current directory structure is as follows:



~/Test/foldername


The directory foldername has all the files that I want to zip. My codes are as follows:



cd Test
tar czvf filename.tar foldername/*






share|improve this question






















  • You can always cd before zipping
    – Weijun Zhou
    Jan 15 at 7:12












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a folder with files which I want to zip into a tar.gz file. I am using the following command:



tar -czvf filename.tar.gz foldername


Sure enough this creates the file filename.tar.gz. However, when I unzip the tar file, by default it creates a folder filename and places all the files into the folder.



Can I avoid this folder creation when I create the tar file itself. I tried the following command but it doesn't work.



tar -czv filename.tar.gz foldername


I am using Ubuntu 14.04.



My current directory structure is as follows:



~/Test/foldername


The directory foldername has all the files that I want to zip. My codes are as follows:



cd Test
tar czvf filename.tar foldername/*






share|improve this question














I have a folder with files which I want to zip into a tar.gz file. I am using the following command:



tar -czvf filename.tar.gz foldername


Sure enough this creates the file filename.tar.gz. However, when I unzip the tar file, by default it creates a folder filename and places all the files into the folder.



Can I avoid this folder creation when I create the tar file itself. I tried the following command but it doesn't work.



tar -czv filename.tar.gz foldername


I am using Ubuntu 14.04.



My current directory structure is as follows:



~/Test/foldername


The directory foldername has all the files that I want to zip. My codes are as follows:



cd Test
tar czvf filename.tar foldername/*








share|improve this question













share|improve this question




share|improve this question








edited Jan 15 at 7:02

























asked Jan 15 at 6:48









popeye

11




11











  • You can always cd before zipping
    – Weijun Zhou
    Jan 15 at 7:12
















  • You can always cd before zipping
    – Weijun Zhou
    Jan 15 at 7:12















You can always cd before zipping
– Weijun Zhou
Jan 15 at 7:12




You can always cd before zipping
– Weijun Zhou
Jan 15 at 7:12










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Another way is to utilize the -C command line argument, as in the following:



tar czvf filename.tar.gz -C foldername .


Note the final ., which tells tar to include "this directory" after having cd-ed into foldername by virtue of the -C foldername argument.



You end up with names in the tar file starting with ./ instead of foldername/, and they thus unpack into the current working directory.



If on the other hand, you have a tar file with names like foldername/X, and you want to un-tar that without the first directory component, then the argument --strip-components=1 is your friend. Thus, the untar command might be:



tar xzf filename.tar.gz --strip-components=1


By that argument, the first directory component of all path names are "stripped away" during the un-tar-ing. Check out man tar for all the details.






share|improve this answer






















  • Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
    – popeye
    Jan 15 at 7:20










  • Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
    – Johan Myréen
    Jan 15 at 7:22










  • @popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
    – Ralph Rönnquist
    Jan 15 at 7:30











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%2f417169%2fcreate-tar-file-that-extracts-only-the-files-and-doesnt-create-folder-during-ex%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
2
down vote













Another way is to utilize the -C command line argument, as in the following:



tar czvf filename.tar.gz -C foldername .


Note the final ., which tells tar to include "this directory" after having cd-ed into foldername by virtue of the -C foldername argument.



You end up with names in the tar file starting with ./ instead of foldername/, and they thus unpack into the current working directory.



If on the other hand, you have a tar file with names like foldername/X, and you want to un-tar that without the first directory component, then the argument --strip-components=1 is your friend. Thus, the untar command might be:



tar xzf filename.tar.gz --strip-components=1


By that argument, the first directory component of all path names are "stripped away" during the un-tar-ing. Check out man tar for all the details.






share|improve this answer






















  • Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
    – popeye
    Jan 15 at 7:20










  • Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
    – Johan Myréen
    Jan 15 at 7:22










  • @popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
    – Ralph Rönnquist
    Jan 15 at 7:30















up vote
2
down vote













Another way is to utilize the -C command line argument, as in the following:



tar czvf filename.tar.gz -C foldername .


Note the final ., which tells tar to include "this directory" after having cd-ed into foldername by virtue of the -C foldername argument.



You end up with names in the tar file starting with ./ instead of foldername/, and they thus unpack into the current working directory.



If on the other hand, you have a tar file with names like foldername/X, and you want to un-tar that without the first directory component, then the argument --strip-components=1 is your friend. Thus, the untar command might be:



tar xzf filename.tar.gz --strip-components=1


By that argument, the first directory component of all path names are "stripped away" during the un-tar-ing. Check out man tar for all the details.






share|improve this answer






















  • Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
    – popeye
    Jan 15 at 7:20










  • Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
    – Johan Myréen
    Jan 15 at 7:22










  • @popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
    – Ralph Rönnquist
    Jan 15 at 7:30













up vote
2
down vote










up vote
2
down vote









Another way is to utilize the -C command line argument, as in the following:



tar czvf filename.tar.gz -C foldername .


Note the final ., which tells tar to include "this directory" after having cd-ed into foldername by virtue of the -C foldername argument.



You end up with names in the tar file starting with ./ instead of foldername/, and they thus unpack into the current working directory.



If on the other hand, you have a tar file with names like foldername/X, and you want to un-tar that without the first directory component, then the argument --strip-components=1 is your friend. Thus, the untar command might be:



tar xzf filename.tar.gz --strip-components=1


By that argument, the first directory component of all path names are "stripped away" during the un-tar-ing. Check out man tar for all the details.






share|improve this answer














Another way is to utilize the -C command line argument, as in the following:



tar czvf filename.tar.gz -C foldername .


Note the final ., which tells tar to include "this directory" after having cd-ed into foldername by virtue of the -C foldername argument.



You end up with names in the tar file starting with ./ instead of foldername/, and they thus unpack into the current working directory.



If on the other hand, you have a tar file with names like foldername/X, and you want to un-tar that without the first directory component, then the argument --strip-components=1 is your friend. Thus, the untar command might be:



tar xzf filename.tar.gz --strip-components=1


By that argument, the first directory component of all path names are "stripped away" during the un-tar-ing. Check out man tar for all the details.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 15 at 8:37

























answered Jan 15 at 7:07









Ralph Rönnquist

2,43738




2,43738











  • Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
    – popeye
    Jan 15 at 7:20










  • Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
    – Johan Myréen
    Jan 15 at 7:22










  • @popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
    – Ralph Rönnquist
    Jan 15 at 7:30

















  • Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
    – popeye
    Jan 15 at 7:20










  • Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
    – Johan Myréen
    Jan 15 at 7:22










  • @popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
    – Ralph Rönnquist
    Jan 15 at 7:30
















Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
– popeye
Jan 15 at 7:20




Ronnquist Thank you. however, my question is about avoiding the folder that gets created when you unzip the tar file. Can I avoid that and unpack the files directly into the directory.
– popeye
Jan 15 at 7:20












Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
– Johan Myréen
Jan 15 at 7:22




Or, alternatively, cd into the directory and run tar cvzf ../filename.tar.gz ..
– Johan Myréen
Jan 15 at 7:22












@popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
– Ralph Rönnquist
Jan 15 at 7:30





@popeye, yes; that's exactly what happens. The very same as what Johan suggests, but with only the tar program doing the cd (not the whole shell)
– Ralph Rönnquist
Jan 15 at 7:30













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f417169%2fcreate-tar-file-that-extracts-only-the-files-and-doesnt-create-folder-during-ex%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)