Find an archive and extract it in the directory where it is located
up vote
0
down vote
favorite
I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?
find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.
I am entirely new to Unix please help me out.Thank you.
shell find tar
add a comment |
up vote
0
down vote
favorite
I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?
find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.
I am entirely new to Unix please help me out.Thank you.
shell find tar
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?
find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.
I am entirely new to Unix please help me out.Thank you.
shell find tar
I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?
find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.
I am entirely new to Unix please help me out.Thank you.
shell find tar
shell find tar
edited Sep 7 '14 at 9:09
ctrl-alt-delor
10.4k41955
10.4k41955
asked Sep 6 '14 at 17:40
CSE
11
11
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02
add a comment |
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
This might help
find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;
From man page of tar
-C, --directory DIR
change to directory DIR
add a comment |
up vote
0
down vote
First is find:
To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.
Now to add your working tar command:
find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf
This will extract all the tar files into the current working directory.
add a comment |
up vote
0
down vote
I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:
find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
This might help
find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;
From man page of tar
-C, --directory DIR
change to directory DIR
add a comment |
up vote
2
down vote
This might help
find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;
From man page of tar
-C, --directory DIR
change to directory DIR
add a comment |
up vote
2
down vote
up vote
2
down vote
This might help
find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;
From man page of tar
-C, --directory DIR
change to directory DIR
This might help
find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;
From man page of tar
-C, --directory DIR
change to directory DIR
edited Sep 7 '14 at 10:14
answered Sep 6 '14 at 19:02
g4ur4v
68451830
68451830
add a comment |
add a comment |
up vote
0
down vote
First is find:
To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.
Now to add your working tar command:
find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf
This will extract all the tar files into the current working directory.
add a comment |
up vote
0
down vote
First is find:
To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.
Now to add your working tar command:
find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf
This will extract all the tar files into the current working directory.
add a comment |
up vote
0
down vote
up vote
0
down vote
First is find:
To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.
Now to add your working tar command:
find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf
This will extract all the tar files into the current working directory.
First is find:
To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.
Now to add your working tar command:
find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf
This will extract all the tar files into the current working directory.
answered Sep 7 '14 at 9:26
ctrl-alt-delor
10.4k41955
10.4k41955
add a comment |
add a comment |
up vote
0
down vote
I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:
find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:
find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
up vote
0
down vote
I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:
find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:
find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago
Tom
1
1
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f154110%2ffind-an-archive-and-extract-it-in-the-directory-where-it-is-located%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08
Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02