Shell – How to pipe the output of tar through mv

mvpipeshell-scripttar

A previous question of mine asked how to pipe downloaded files through tar, now I would like to know how to pipe the output of tar through mv. See I have this command at the moment:

wget -c https://github.com/JeffHoogland/moksha/archive/0.1.0.tar.gz | tar -xz

and this creates a directory called moksha-0.1.0, but I would like to know how I might rename this output directory as moksha, perhaps via a pipe (|) at the end of this command. Although if you know how to do this without a pipe, but still on the same line of code as wget and tar, I will be happy to accept it too.

To be clear I know that:

wget -c https://github.com/JeffHoogland/moksha/archive/0.1.0.tar.gz | tar -xz -C moksha

will create an output directory moksha but within this output directory there will be the moksha-0.1.0 directory, rather I want to rename this moksha-0.1.0 directory as moksha, instead of placing moksha-0.1.0 in a new directory called moksha.

Best Answer

Like this?

[root@b se]# wget -cqO - https://github.com/JeffHoogland/moksha/archive/0.1.0.tar.gz | tar -xz --transform=s/moksha-0.1.0/moksha/
[root@b se]# ls
moksha
[root@b se]# ls moksha
ABOUT-NLS       config.guess          debian                 Makefile.am
aclocal.m4      config.guess.dh-orig  depcomp                Makefile.in
AUTHORS         config.h.in           doc                    missing
autogen.sh      config.rpath          enlightenment.pc.in    netwm.txt
autom4te.cache  config.sub            enlightenment.spec.in  NEWS
BACKPORTS       config.sub.dh-orig    INSTALL                po
BUGS            configure             install-sh             README
ChangeLog       configure.ac          intl                   src
compile         COPYING               ltmain.sh              xdebug.sh
config          data                  m4                     x-ui.sh

From the tar manual page:

--transform=EXPRESSION, --xform=EXPRESSION
    Use sed replace EXPRESSION to transform file names.

So sed is probably required for this to work. Though if you have wget, you probably have sed as well.

Related Question