Using a tar file in a command like a file
Why?
This allows you to extract the tar file into another process like a file to avoid extracting it to local disk (which may have insufficient capacity) running the command on it and then deleting the extracted file.
as an example I needed to add an image to glance. The extracted file was 30GB, the tar file was 7GB and there was only 31GB free on the node I was logged into. It doesn't fit!
The file is: Hystax_Acura_VA_MGR_OpenStack_20190506_3.0.383-release_3.0.tar.gz and contains a RAW disk image called Hystax_Acura_VA_MGR_OpenStack_20190506_3.0.383-release_3.0
normally to add this I would do
tar zxf Hystax_Acura_VA_MGR_OpenStack_20190506_3.0.383-release_3.0.tar.gz
and then
openstack image create --disk-format raw --file ./Hystax_Acura_VA_MGR_OpenStack_20190506_3.0.383-release_3.0 Hystax
to do this in one step we can use process substitution to redirect the output of tar to a filehandle and push the output of tar to stdout like this
How
openstack image create --disk-format raw --file <(tar --to-stdout -zxf ./Hystax_Acura_VA_MGR_OpenStack_20190506_3.0.383-release_3.0.tar.gz) Hystax_decomp
the important bit is the <() construction this redirects stdout from the process inside to the --file argument of openstack image create
The next important part is the --to-stdout flag for tar which IF YOU HAVE THE RIGHT tar version can be integrated as tar -zx0f. the rest is unchanged. remember to use jxf if presented with a tar.bz2 instead.