Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .