I want to download a file, untar it and rename the folder.
I am able to download the file and untar it with
curl https://s3.amazonaws.com/sampletest/sample.tar.gz | tar xz
How can I rename the folder in the same command?
curl https://s3.amazonaws.com/sampletest/sample.tar.gz | tar xz | mv ???????
I do not want to use the folder name explicitly in the command.
It's possible, but not trivial. It's easier to create your own directory, cd into it, then pass --strip-components 1
or --strip-path 1
to tar
if your tar (e.g. GNU Tar) supports it.
File name transformations:
--strip-components=NUMBER strip NUMBER leading components from file
names on extraction
--transform=EXPRESSION, --xform=EXPRESSION
use sed replace EXPRESSION to transform file names
If your system hasn't GNU tar
installed, it might still have pax
(a POSIX tool) available. The latter supports the -s
option which allows arbitrary changes in the path name of the processed files.
That would then be:
curl https://s3.amazonaws.com/sampletest/sample.tar.gz | gunzip | pax -r -s "/old/new/"