Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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