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.

system("tar -czf #{RAILS_ROOT}/tmp/export-result #{RAILS_ROOT}/tmp/export")

When I decompress the resulting file I get

app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp/export/and_the_files

I would like to just get:

export_result/and_the_files

How do I change my TAR call to accomplish this?

solution:

system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/")

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This is how you do it,

tar cfz target.tgz --directory=TARGET_DIR subdir_list

In your case it would look like,

tar cfz target.tgz --directory=app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp export/
share|improve this answer
    
So, first I specify where I want to save the result 'target.tgz' then I specify where the contents are and what subdirs should be removed. Correct? –  Nerian Feb 19 '11 at 13:28
    
This is an app hosted at Heroku, so the only place where I can write is RAILS_ROOT/tmp/ how do I write it so that target.tgz end up there? –  Nerian Feb 19 '11 at 13:31
    
I did it: system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/") –  Nerian Feb 19 '11 at 13:43
    
right! Good for you :-) –  nik Feb 19 '11 at 18:27
add comment

Change to #{RAILS_ROOT} before compression and don't specify it in the source files.

share|improve this answer
add comment

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.