3

I have some directories, I want to pack into a tgz archive:

/home/stofl/myproject/migrations/
/home/stofl/myproject/source/
/path/to/my/migration/tool/source/

The archive should have the following structure:

migrations/
source/
my_migration_tool/

Do I have to copy the migration tool into /home/stofl/myproject/ (or create a symlink) or is there another way?

EDIT

The archive could be compressed with gzip later. So maybe there is a way to append the directory to the tar archive with --append, but I didn't find a way to tell tar to use a different name.

3

As the archive should have relative paths (migrations/ source/ my_migration_tool/) there would have to be an archive made from /home/stofl/myproject.

As you mention you could append a directory to the tar archive (tar only permits appending for non-gzipped archives). But this would not rename the 3rd directory to my_migration_source:

cd /home/stofl/myproject
tar cvf myprojects.tar migrations source
/path/to/my/migration
# appends contents of tool to archive
tar -rv --file /home/stofl/myproject/myprojects.tar tool 

The easiest option I think would be to use a symbolic link-:

cd /home/stofl/myprojec 
ln -s my_migration_tool /path/to/my/migration/tool/source/
# tar H option to follow symbolic links
tar cvfH myprojects.tar migrations source my_migration_tool
  • Yes thank you. I think I'll do that (but the option is h, not H, I think). I found an --xfrom parameter, but thats a bit too much for me now to find the right expression (if there is one). – stofl Mar 26 '13 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.