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

Clash 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/*
ubuntu tar
add a comment |Â
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/*
ubuntu tar
You can alwayscdbefore zipping
â Weijun Zhou
Jan 15 at 7:12
add a comment |Â
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/*
ubuntu tar
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/*
ubuntu tar
edited Jan 15 at 7:02
asked Jan 15 at 6:48
popeye
11
11
You can alwayscdbefore zipping
â Weijun Zhou
Jan 15 at 7:12
add a comment |Â
You can alwayscdbefore 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
add a comment |Â
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.
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 runtar 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 thetarprogram doing thecd(not the whole shell)
â Ralph Rönnquist
Jan 15 at 7:30
add a comment |Â
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.
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 runtar 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 thetarprogram doing thecd(not the whole shell)
â Ralph Rönnquist
Jan 15 at 7:30
add a comment |Â
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.
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 runtar 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 thetarprogram doing thecd(not the whole shell)
â Ralph Rönnquist
Jan 15 at 7:30
add a comment |Â
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.
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.
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 runtar 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 thetarprogram doing thecd(not the whole shell)
â Ralph Rönnquist
Jan 15 at 7:30
add a comment |Â
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 runtar 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 thetarprogram doing thecd(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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You can always
cdbefore zippingâ Weijun Zhou
Jan 15 at 7:12