0
current directory
            ├──Folder1
                ├── sub_folder1
            ├──Folder2
                ├── sub_folder21
                ├── sub_folder22
                      ├── sub_folder221
            ├──Folder3
                ├── sub_folder31
            ├──Folder4
                ├── sub_folder41
            ├──Folder5
                ├── sub_folder51

Given the above folder subfolder hierarchy, which was compressed into one tgz file, I need to extract all files present in any folders subfolders, into one and only output directory.
Actually all files exist in the deepest path of each folder subfolder combination. for example in sub_folder1,sub_folder2, sub_folder221, etc. I have tried with the following:

find . -name '*.tar.gz' -execdir tar -xzvf '{}' \;

...but that outputs the exact hierarchy of files and subfolders, when I need all files in all subfolders, to be extracted to just one output folder /path/to/one/folder

1
  • Unclear: do you have one tar file or many?  (You indicate both.)  Also, show all the commands you have tried and their results.  Please do not respond in comments; edit your question to make it clearer and more complete. Oct 11, 2018 at 16:34

1 Answer 1

1

The execdir is exactly the wrong command for your task, it will change to the directory of the file.

If you use -exec, the working directory will stay the same and all tar files will be extracted from that directory.

There is also the option -C to make tar change to that directory.

find . -name '*.tar.gz' -exec tar xzvfC '{}' /path/to/one/folder \;

or

find . -name '*.tar.gz' -exec tar -xzvf '{}' -C /path/to/one/folder \;
3
  • Try the command I added.
    – RalfFriedl
    Oct 11, 2018 at 15:22
  • i get following error:tar (child): C: Cannot open: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2. i also edited my question, perhaps it was missleading tar: Error is not recoverable: exiting now
    – cezudun
    Oct 11, 2018 at 15:31
  • Try the changed commands.
    – RalfFriedl
    Oct 11, 2018 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .