Added on Apr 30th, 2015 and marked as cli tar

When you extract a tar archive, by default the files and directories will be extracted to the current working directory. If you want to extract them to a different directory, it is possible to use the -C (or --directory) option:

tar xvf archive.tar -C /path/to/target/directory

Note: The target directory must exist. tar will not create it for you.

If the tarball already contains a directory (all files and subdirectories are stored in a general directory), then it is possible to add the --strip-components <count> option to extract the content at the desired location without having to move them afterwards:

tar xvf archive.tar -C /path/to/target/directory --strip-components 1