How can I create a compressed tar in sun solaris?

To avoid creation of temporary intermediate file you can use this command

tar cvf - directory1|gzip -c >file.tar.gz

Looks like Solaris's tar doesn't know how to compress. So just do it manually:

tar -cvf file.tar directory1 && gzip file.tar

That's all the -z switch of GNU tar does, anyway. The command above will produce file.tar.gz.

Check if you haveSUNWgtar installed. This the the GNU version of tar and provides /usr/sfw/bin/gtar which will allow the use of the GNU options to tar.