Tar Command – How to Extract Files to Another Directory

tar

I thought tar archive.tar /users/mylocation would work, but it doesn't. How can I do that?

Best Answer

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

Note that the target directory has to exist before running that command (it can be created by mkdir /target/directory).

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