Make a symlink first, and have tar follow it.
ln -s project-root something-else
tar cjf foo.tar.bz2 something-else/*
rm something-else
The /*
is necessary to follow the link and select all the contents rather than just tarring the symlink itself. You could alternatively use the -h
option on GNU tar (but this will also follow links inside, which you may not want to do) or the H
option on BSD tar (like on a Mac).
You could even do this from inside project-root:
cd project-root
ln -s . something-else
tar cjf foo.tar.bz2 --exclude=something-else/something-else something-else/*
rm something-else
Unless you explicitly exclude it (as above), the symlink will exist in the tarball too.
Obviously if you are doing this lots of times and don't mind the symlink hanging around it doesn't have to be deleted and recreated each time.
Meaning to say, the extracting user shouldn't have to know what something-else should be (i.e. mkdir it), it's the compressing user that specifies it. – Pistos – 2010-01-20T01:11:26.313
It sounds like you're asking, "If the user extracts the whole archive, create project-root subdirectory. If the user extracts just part of the archive, then call the subdirectory something-else." If not, then just name the directory something-else in the first place. – Stephen Jennings – 2010-01-20T01:50:40.123
Imagine the original directory is called project/, and I want to make tarballs for project-0.1, project-0.2, and so on. Renaming the dir each time doesn't seem optimal. It would be better suited as an option on tar. – Pistos – 2010-01-20T02:40:40.820
yeah. what you're talking about borders on "version control", and is slightly outside
tar
's scope (which is why there's no option for it). generally if you have a project and want to make a point release, you'd use your version control tools to set certain versions of certain files as project v0.1, or v0.2, etc. then checkout the v0.1 files to a new directory project-0.1, tar that directory, and tahdaaaah, done. – quack quixote – 2010-01-20T02:44:46.600