Do not create the tar file in the directory you are building:
tar -czf /tmp/workspace.tar.gz .
does the trick, except that it will extract files all over the current directory when unpacking. Better to do:
cd .. tar -czf workspace.tar.gz workspace
or, if you do not know the name of the directory in which you were:
base=$(basename $PWD) cd .. tar -czf $base.tar.gz $base
(It is assumed that you did not follow symbolic links to get to where you are, and that the shell does not try to guess you by jumping back over a symbolic link - bash not trustworthy in this regard. You need to worry about this, use cd -P .. to create a directory of physical changes. It's silly that this is not the default behavior on my view - confusing, at least for those for whom cd .. has never been an alternative value.)
One comment in the discussion says:
I [...] need to exclude the top directory, and I [...] need to put tar in the base directory.
The first part of the comment does not make much sense - if the tar file contains the current directory, it will not be created when the file is extracted from this archive, because by definition the current directory already exists (except for very strange circumstances).
The second part of the comment can be considered in one of two ways:
- Or: create a file somewhere else -
/tmp - one of the possible places - and then return it to its original location after its completion. - Or: if you use GNU Tar, use the
--exclude=workspace.tar.gz option. The line after = is a pattern - an example is the simplest pattern - an exact match. You may need to specify --exclude=./workspace.tar.gz if you work in the current directory contrary to recommendations; you may need to specify --exclude=workspace/workspace.tar.gz if you work on the same level as suggested. If you have several tar files for exclusion, use ' * ', as in --exclude=./*.gz .
Jonathan Leffler Sep 06 '10 at 16:01 2010-09-06 16:01
source share