0

I've this command:

zip files/test.zip $(tar tf files/test.gz)

But it doesn't work because everything from $(tar tf files/test.gz) are in files/ So zip can't find it. It works perfectly if I change directory to files and exec this one:

zip test.zip $(tar tf test.gz)

But I need to make it work from parent directory.

My full command is:

tar xzf files/test.tar.gz && zip files/test.zip $(tar tf files/test.tar.gz) && rm -r -- $(tar tf files/test.tar.gz)

From Is there any command on Linux to convert .tar.gz files to .zip?

Thank you

Splinteer
  • 1,126
  • 4
  • 13
  • 28
  • why can't you pushd, enter the `files` execute the cmd, then popd? what is your real problem? you want to zip all files in the tar? or you want to zip files with same filenames in tar? – Kent Sep 25 '18 at 11:03
  • @Kent I want to convert my tar.gz to zip – Splinteer Sep 25 '18 at 11:03

1 Answers1

0

I would make a little script for that. If you have many tgz files to handle, you can apply a loop on it.

#!/bin/bash
TMP=/a/tmp/directory
TARGET=/dir/to/your/files
mkdir -p $TMP   
cd $TMP
tar -C $TMP -xzf $TARGET/your.tar.gz && zip $TARGET/your.zip *  
rm -rf $TMP
Kent
  • 189,393
  • 32
  • 233
  • 301
  • This will add the temp directory inside zip file. -j argument doesn't work here because I only want to remove the first directory if there is some more – Splinteer Sep 25 '18 at 14:38