Untar single file to desired name
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
When I tar
a single file, I can give the tar
file a desired name:
$ tar -cvfj A B
I would like to do the same when I untar a single file.
$ tar -xvjf A tmp
(ie. extract A
into tmp
).
I was trying to do this using mv
:
$ tar -xvjf $1 | mv $1 tmp
That didn't work. $1
can be an arbitrary name, but the tar
files will always be a single file, no folders (this is guaranteed).
tar
add a comment |Â
up vote
4
down vote
favorite
When I tar
a single file, I can give the tar
file a desired name:
$ tar -cvfj A B
I would like to do the same when I untar a single file.
$ tar -xvjf A tmp
(ie. extract A
into tmp
).
I was trying to do this using mv
:
$ tar -xvjf $1 | mv $1 tmp
That didn't work. $1
can be an arbitrary name, but the tar
files will always be a single file, no folders (this is guaranteed).
tar
Are you just usingtar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)
â Fox
Sep 2 at 20:27
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
3
If your local tar implementation does not create a file namedj
in your first example, it is broken.
â schily
Sep 2 at 20:31
1
Use-C
:tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
When I tar
a single file, I can give the tar
file a desired name:
$ tar -cvfj A B
I would like to do the same when I untar a single file.
$ tar -xvjf A tmp
(ie. extract A
into tmp
).
I was trying to do this using mv
:
$ tar -xvjf $1 | mv $1 tmp
That didn't work. $1
can be an arbitrary name, but the tar
files will always be a single file, no folders (this is guaranteed).
tar
When I tar
a single file, I can give the tar
file a desired name:
$ tar -cvfj A B
I would like to do the same when I untar a single file.
$ tar -xvjf A tmp
(ie. extract A
into tmp
).
I was trying to do this using mv
:
$ tar -xvjf $1 | mv $1 tmp
That didn't work. $1
can be an arbitrary name, but the tar
files will always be a single file, no folders (this is guaranteed).
tar
edited Sep 3 at 4:00
slmâ¦
237k65486659
237k65486659
asked Sep 2 at 20:11
Spent Death
254
254
Are you just usingtar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)
â Fox
Sep 2 at 20:27
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
3
If your local tar implementation does not create a file namedj
in your first example, it is broken.
â schily
Sep 2 at 20:31
1
Use-C
:tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43
add a comment |Â
Are you just usingtar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)
â Fox
Sep 2 at 20:27
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
3
If your local tar implementation does not create a file namedj
in your first example, it is broken.
â schily
Sep 2 at 20:31
1
Use-C
:tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43
Are you just using
tar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)â Fox
Sep 2 at 20:27
Are you just using
tar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)â Fox
Sep 2 at 20:27
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
3
3
If your local tar implementation does not create a file named
j
in your first example, it is broken.â schily
Sep 2 at 20:31
If your local tar implementation does not create a file named
j
in your first example, it is broken.â schily
Sep 2 at 20:31
1
1
Use
-C
: tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43
Use
-C
: tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
Since you seem to be using tar
with bzip2
compression as a way of just compressing a single file, you may want to consider using bzip2
directly:
To compress a file (creates filename.bz2
, deletes filename
):
bzip2 filename
To decompress a file (creates filename
, deletes filename.bz2
):
bunzip2 filename.bz2
To compress to a specific filename (creates newfilename.bz2
, keeps filename
):
bzip2 -c filename >newfilename.bz2
To decompress to a specific filename (creates newfilename
, keeps filename.bz2
):
bunzip2 -c filename.bz2 >newfilename
See also the manual for bzip2
on your system (man bzip2
).
I like this solution. However, there is a file that has spaces. How can my bash script handle this?./decomp "blah blah blah.bz2"
gets all messed up. When I usedbunzip2
directly, it's all good.
â Spent Death
Sep 2 at 21:47
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
1
@SpentDeath That means that rather than$1
, you'd use"$1"
so that your arguments don't get split
â Fox
Sep 3 at 0:22
add a comment |Â
up vote
7
down vote
Here is one solution:
tar -xjOf my.tar > out
This uses the -O
option of tar
-O, --to-stdout
: extract files to standard output
and redirects standard output to a file called out
. If the archive has more than one file, out
will be all of the files in the archive concatenated.
You should probably just be using bzip2
directly, as during compression it will not store a file tree. Instead, it will simply store the data within the file.
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
Since you seem to be using tar
with bzip2
compression as a way of just compressing a single file, you may want to consider using bzip2
directly:
To compress a file (creates filename.bz2
, deletes filename
):
bzip2 filename
To decompress a file (creates filename
, deletes filename.bz2
):
bunzip2 filename.bz2
To compress to a specific filename (creates newfilename.bz2
, keeps filename
):
bzip2 -c filename >newfilename.bz2
To decompress to a specific filename (creates newfilename
, keeps filename.bz2
):
bunzip2 -c filename.bz2 >newfilename
See also the manual for bzip2
on your system (man bzip2
).
I like this solution. However, there is a file that has spaces. How can my bash script handle this?./decomp "blah blah blah.bz2"
gets all messed up. When I usedbunzip2
directly, it's all good.
â Spent Death
Sep 2 at 21:47
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
1
@SpentDeath That means that rather than$1
, you'd use"$1"
so that your arguments don't get split
â Fox
Sep 3 at 0:22
add a comment |Â
up vote
7
down vote
accepted
Since you seem to be using tar
with bzip2
compression as a way of just compressing a single file, you may want to consider using bzip2
directly:
To compress a file (creates filename.bz2
, deletes filename
):
bzip2 filename
To decompress a file (creates filename
, deletes filename.bz2
):
bunzip2 filename.bz2
To compress to a specific filename (creates newfilename.bz2
, keeps filename
):
bzip2 -c filename >newfilename.bz2
To decompress to a specific filename (creates newfilename
, keeps filename.bz2
):
bunzip2 -c filename.bz2 >newfilename
See also the manual for bzip2
on your system (man bzip2
).
I like this solution. However, there is a file that has spaces. How can my bash script handle this?./decomp "blah blah blah.bz2"
gets all messed up. When I usedbunzip2
directly, it's all good.
â Spent Death
Sep 2 at 21:47
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
1
@SpentDeath That means that rather than$1
, you'd use"$1"
so that your arguments don't get split
â Fox
Sep 3 at 0:22
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
Since you seem to be using tar
with bzip2
compression as a way of just compressing a single file, you may want to consider using bzip2
directly:
To compress a file (creates filename.bz2
, deletes filename
):
bzip2 filename
To decompress a file (creates filename
, deletes filename.bz2
):
bunzip2 filename.bz2
To compress to a specific filename (creates newfilename.bz2
, keeps filename
):
bzip2 -c filename >newfilename.bz2
To decompress to a specific filename (creates newfilename
, keeps filename.bz2
):
bunzip2 -c filename.bz2 >newfilename
See also the manual for bzip2
on your system (man bzip2
).
Since you seem to be using tar
with bzip2
compression as a way of just compressing a single file, you may want to consider using bzip2
directly:
To compress a file (creates filename.bz2
, deletes filename
):
bzip2 filename
To decompress a file (creates filename
, deletes filename.bz2
):
bunzip2 filename.bz2
To compress to a specific filename (creates newfilename.bz2
, keeps filename
):
bzip2 -c filename >newfilename.bz2
To decompress to a specific filename (creates newfilename
, keeps filename.bz2
):
bunzip2 -c filename.bz2 >newfilename
See also the manual for bzip2
on your system (man bzip2
).
edited Sep 2 at 21:06
answered Sep 2 at 20:52
Kusalananda
105k14209326
105k14209326
I like this solution. However, there is a file that has spaces. How can my bash script handle this?./decomp "blah blah blah.bz2"
gets all messed up. When I usedbunzip2
directly, it's all good.
â Spent Death
Sep 2 at 21:47
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
1
@SpentDeath That means that rather than$1
, you'd use"$1"
so that your arguments don't get split
â Fox
Sep 3 at 0:22
add a comment |Â
I like this solution. However, there is a file that has spaces. How can my bash script handle this?./decomp "blah blah blah.bz2"
gets all messed up. When I usedbunzip2
directly, it's all good.
â Spent Death
Sep 2 at 21:47
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
1
@SpentDeath That means that rather than$1
, you'd use"$1"
so that your arguments don't get split
â Fox
Sep 3 at 0:22
I like this solution. However, there is a file that has spaces. How can my bash script handle this?
./decomp "blah blah blah.bz2"
gets all messed up. When I used bunzip2
directly, it's all good.â Spent Death
Sep 2 at 21:47
I like this solution. However, there is a file that has spaces. How can my bash script handle this?
./decomp "blah blah blah.bz2"
gets all messed up. When I used bunzip2
directly, it's all good.â Spent Death
Sep 2 at 21:47
1
1
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
@SpentDeath Make sure that you double quote the variable expansion in your script.
â Kusalananda
Sep 2 at 21:52
what does that mean?
â Spent Death
Sep 2 at 21:59
what does that mean?
â Spent Death
Sep 2 at 21:59
1
1
@SpentDeath That means that rather than
$1
, you'd use "$1"
so that your arguments don't get splitâ Fox
Sep 3 at 0:22
@SpentDeath That means that rather than
$1
, you'd use "$1"
so that your arguments don't get splitâ Fox
Sep 3 at 0:22
add a comment |Â
up vote
7
down vote
Here is one solution:
tar -xjOf my.tar > out
This uses the -O
option of tar
-O, --to-stdout
: extract files to standard output
and redirects standard output to a file called out
. If the archive has more than one file, out
will be all of the files in the archive concatenated.
You should probably just be using bzip2
directly, as during compression it will not store a file tree. Instead, it will simply store the data within the file.
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
add a comment |Â
up vote
7
down vote
Here is one solution:
tar -xjOf my.tar > out
This uses the -O
option of tar
-O, --to-stdout
: extract files to standard output
and redirects standard output to a file called out
. If the archive has more than one file, out
will be all of the files in the archive concatenated.
You should probably just be using bzip2
directly, as during compression it will not store a file tree. Instead, it will simply store the data within the file.
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Here is one solution:
tar -xjOf my.tar > out
This uses the -O
option of tar
-O, --to-stdout
: extract files to standard output
and redirects standard output to a file called out
. If the archive has more than one file, out
will be all of the files in the archive concatenated.
You should probably just be using bzip2
directly, as during compression it will not store a file tree. Instead, it will simply store the data within the file.
Here is one solution:
tar -xjOf my.tar > out
This uses the -O
option of tar
-O, --to-stdout
: extract files to standard output
and redirects standard output to a file called out
. If the archive has more than one file, out
will be all of the files in the archive concatenated.
You should probably just be using bzip2
directly, as during compression it will not store a file tree. Instead, it will simply store the data within the file.
answered Sep 2 at 20:41
Cebtenzzre
711
711
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
add a comment |Â
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
3
3
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
Caveat of this approach is you do not preserve metadata like permissions and symlinks.
â Bob
Sep 3 at 5:07
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%2f466445%2funtar-single-file-to-desired-name%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
Are you just using
tar
for compression? If so, don't do that; just use the compression program directly (bzip2
in your case)â Fox
Sep 2 at 20:27
@Fox yes, I am. What difference does it make?
â Spent Death
Sep 2 at 20:28
3
If your local tar implementation does not create a file named
j
in your first example, it is broken.â schily
Sep 2 at 20:31
1
Use
-C
:tar -xvjf $1 -C tmp
â GAD3R
Sep 2 at 20:43