
Tengo un archivo doblemente comprimido ( .tar.gz
dentro de a .tar
) y me gustaría saber si hay alguna forma de extraerlo automáticamente de un script bash. Probé dos enfoques:
tar -xf $1 #the first .tar file is passed as argument to the bash script
tar -xf /home/user/working_dir/file_inside.tar.gz #passing the absolute path to the file assuming the .tar file was extracted as expected.
tar -xf $1 | tar -xf `xargs`
Pero me sale el error: tar: /file_inside.tar.gz: Cannot open: No such file or directory
.
Gracias de antemano.
Respuesta1
Si conoce el nombre de archivo relativo del archivo intermedio, intente
tar -xf $1 -O path/to/file.tar.gz | tar xf -
dónde
-O, --to-stdout Extract files to standard output.
es posible que necesites
-z
una bandera en el segundo alquitrántenga en cuenta que
-
es sinónimo de stdin, ¿tal vez eso es lo que quiso decir (tar -xf $1 | tar -xf xargs
(*))?tar -xf $1 | tar -xf -
(*) xargs está entrecomillado
Si te sientes aventurero, también puedes probar la opción--to-command=COMMAND
tar -xf $1 --to-command="tar -xzf -" path/to/file
- Aconsejo hacer una prueba antes de pasar a "producción".
- No usar ruta absoluta