Michal Artazov
Michal Artazov

Reputation: 4648

Bash create .tar.gz on Solaris

I'm writting a bash script, which should create a .tar.gz archive from specified directory including file structure. This is a homework and I need it to work on Solaris system my school uses. That means I can't use tar like this

tar xvzf archive.tar.gz ./

because this system uses some older version of tar without -z option. I use it like this

tar xvf - ./ | gzip > archive.tar.gz

It works fine except a strange fact, that when I examine contents of the archive, it contains itself (in other words, it contains "archive.tar.gz"). How can I prevent this?

Upvotes: 0

Views: 10524

Answers (2)

BentheFolker
BentheFolker

Reputation: 301

This works: tar cvf - | gzip > archive.tar.gz

Upvotes: 1

user2256686
user2256686

Reputation: 245

Thing is, that file named "archive.tar.gz" is created immediately when you run your command. Meaning, before gzip is called. It's just blank file, but it is in directory. To prevent including it into resulting archive, you can try to modify your script in one of following ways:

  1. tar xvf - ./ | gzip > ../archive.tar.gz
  2. tar xvf - {path_to_dir_you_want_to_compress_files_from} | gzip > archive.tar.gz

Sadly, I can't check if either of this scripts works, because I don't have Solaris anywhere. Please, let me know if any of that works.

Upvotes: 0

Related Questions