2
There are many folders in my current directory. Each folder has a tar.gz file. To extract the tar.gz file I need to be inside each folder and run the following command every time.
tar xvzf tar.gz -C /path/to/targetdirectory
Inside my current directory it looks like below:
current directory
├──Folder1
├── A.tar.gz
├──Folder2
├── B.tar.gz
├──Folder3
├── C.tar.gz
├──Folder4
├── D.tar.gz
├──Folder5
├── E.tar.gz
To extract all at a time I tried like this
tar xvzf */*.tar.gz -C /path/to/targetdirectory
This gave me an error:
tar: Folder1/A.tar.gz: Not found in archive
tar: Folder2/B.tar.gz: Not found in archive
tar: Folder3/C.tar.gz: Not found in archive
tar: Folder4/D.tar.gz: Not found in archive
tar: Folder5/E.tar.gz: Not found in archive
Where should I give target directory in the command? – beginner – 2018-03-27T13:27:45.340
Ok. Gave like this to get the extracted files into target directory. find . -name '*.tar.gz' -execdir tar -C /path/to/targetdirectory -xzvf '{}' ; This worked – beginner – 2018-03-27T14:20:25.033
Yep, you can specify the commands as usual within the
-exec
option. – slhck – 2018-03-27T14:30:12.563hi...I have small doubt. Is there a way to give path to those...*.tar.gz files? – beginner – 2018-04-12T15:16:18.543
You can
find
in another directory by replacingfind .
withfind /path/to/directory
. – slhck – 2018-04-13T07:02:24.497