You want to create a tar file away from the place the files you need to tar reside?
There are many ways to do this.
If it is to be created locally (= on the same machine) :
tar czvf /path/to/destination/newfile.tar.gz ./SOURCEDIR_OR_FILES
You can add additionnal files or directories to tar at the end of that command.
If it is to be created remotely (ie, you want to create the tar file on a remote host from the one containing the data to be tared):
tar czvf - ./SOURCEDIR_OR_FILES | ssh user@host 'cat > newfile.tar.gz'
The later version is very versatile. For example you can also "duplicate" a directory + subdirs using the same technique:
Duplicate a directory+subdirs to another local directory:
tar cf - ./SOURCEDIR_OR_FILES | ( cd LOCAL_DEST_DIR && tar xvf - )
Duplicate a directory+subdirs to another remote directory:
tar cvf - ./SOURCEDIR_OR_FILES | ssh user@host 'cd REMOTE_DEST_DIR && tar xf - '
Drop the 'v' if you don't need it to display files as they are tar-ed (or untarred): it will then go much faster, but won't say much unless there is an error.
I use "./..." for the source to force tar to store it as a RELATIVE path. In some cases you'll want to add additionnal path information:
For example to tar the crontab files, including the one in /etc, you could do:
cd / ; tar czf all_crons.tgz ./etc/*cron* ./var/spool/cron
I use on purpose the relative path: some OLD versions of tar may be dangerous and extract files with their original GLOBAL path, meaning you could do : cd /safedir ; tar xvf sometar and have the files with global names overwrite files at their original path, which is OUTSIDE of /safedir and not underneath it! Very dangerous, and still possible as there are old production servers out there. Better to be used to use relative paths all the time, even if you use a more recent tar.
cd /opt; tar zcf $HOME/junk.tar.gz junk. – vonbrand Jan 23 at 16:37