Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I think tar archive.tar /users/mylocation will work. But it doesn't. How can I do that?

share|improve this question
1  
grep the 'man' like tar --help | grep directory –  Ujjwal Singh May 8 at 18:01
add comment

2 Answers 2

up vote 133 down vote accepted

To extract an archive to a directory different from the current, use the -C, or --directory, tar option, as in

tar -xf archive.tar -C /target/directory

Read the manual page (command: man tar) for other options.

share|improve this answer
2  
Thank u! It works! –  goovim May 27 '11 at 1:42
3  
I read the man page, but couldn't figure out what to search for. Thanks for this answer! –  Topher Fangio Apr 24 '13 at 20:41
8  
You have to create the directory manually though. –  Pineapple Under the Sea May 16 '13 at 10:01
add comment

Note that if your tarball already contains a directory name you want to change, add the --strip-components=1 option:

tar xf archive.tar -C /target/directory --strip-components=1
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.