-1

Next problem is taking place for me:

There is TAR archive i had to compile with file-roller for a while as script routine using file-roller command. Now I had to change my script to be more "technical" and cross-platform referring directly to TAR command: For this i just cd to specific directory and using this command:

tar -cvzf "path/to/archive.tar.gz" "." > /dev/null 2>&1

The problem that "." directory is transformed into path inside the archive and files are stored under subdirectory "." in next manner:

archive.tar.gz
-> ./
   -> file1.ext
   -> file2.ext

I've managed to use --transform option to get the files back into root folder of archive this way:

tar -cvzf "path/to/archive.tar.gz" --transform "s,.,," "." > /dev/null 2>&1

The result is right organized archive with files moved to archive root folder:

archive.tar.gz
-> file1.ext
-> file2.ext

The outcoming archive readable by file-roller, while has broken functionality on file extraction by tar:

tar -x -f "path/to/archive.tar" -C "$TEMP_DIR/" file1.ext

TAR has immediately to report: No such file or directory in archive or similar.

tar -x -f "path/to/archive.tar" -C "$TEMP_DIR/"

Still works normally and extracts all files from archive into "$TEMP_DIR/".

LifeOnNet
  • 107
  • 2
  • 13
  • I've never worked with `--transform`, so I give this only as a comment, not an answer. Your `--transform "s,.,,"` removes, as far I can tell, all periods from the file names, or at least the first period encountered in each name. But you want to extract a file named `tarred-file.ext`, which does have a period, so it can't find the file. Use the option `--show-transformed-names` to display the effect of your `transform`. – user1934428 Apr 29 '20 at 13:38
  • You can do `tar -tvf yourfile.tar` to see the contents of a tar file (the `-t` option). – Nic3500 Apr 29 '20 at 13:49

1 Answers1

0

You need to get rid of the first dot and slash :

tar -cvzf "path/to/archive.tar.gz" --transform "s,./,," "." > /dev/null 2>&1

Or you can simply do (if you don't have hidden files)

tar -cvzf "path/to/archive.tar.gz" * > /dev/null 2>&1

For extraction, you can run directly on tar.gz :

tar zxf "path/to/archive.tar.gz" -C "$TEMP_DIR/" tarred-file.ext
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • Well said! It's finally working now, BUT it still has /./ directory inside archive, with small difference that now the files archived are outside it directly in root directory. I can make a suggestion why it goes but got no idea how to get rid of this. – LifeOnNet Apr 29 '20 at 15:18
  • You will not have that entry, if you use the second form. – Philippe Apr 29 '20 at 15:33
  • Well, more weird findings are coming: following your instructions first form is leaving me with empty self-reference to current directory archived inside tar (as described before). Second form appears to be kind of "unviable" for me, and leaves me with tarball says "stat command failed, No such file or directory" @Philippe – LifeOnNet Apr 29 '20 at 16:54
  • `empty self-reference to current directory archived inside tar` should not matter. `No such file or directory` is when you do `tar` or `untar` ? – Philippe Apr 29 '20 at 16:59
  • While doing `tar`. The confusion about self-reference is coming due to one's unexistense while creating file through `file-roller` @Philippe – LifeOnNet Apr 29 '20 at 17:43