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
grep the 'man' like tar --help | grep directory –  Ujjwal Singh May 8 '14 at 18:01
@UjjwalSingh I would not search help or manpages like that... Enter man COMMAND then press / and type your search phrase. To search multiple manpages, enter apropos PHRASE or man -K PHRASE. –  Six Feb 13 at 19:20

2 Answers 2

up vote 289 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
Thank u! It works! –  goovim May 27 '11 at 1:42
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
You have to create the directory manually though. –  Mich May 16 '13 at 10:01
The number of times I've had to look this up is getting a little ridiculous. –  ConsultStan Jul 29 '14 at 13:16
Can the path be stripped: i.e just retrieve the file –  zzapper Aug 26 '14 at 14:52

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

Your Answer


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.