To extract a tar
archive to a different directory, you can use the tar
command with the -C
option. The -C
option allows you to specify the destination directory where the files will be extracted.
Here’s an example:
tar -xf archive.tar.gz -C /path/to/destination
In this example, the -xf
options specify that the archive should be extracted (-x
) and the file is compressed using gzip (-f
). The -C /path/to/destination
option specifies the destination directory where the files will be extracted.
Note that you can also extract other types of archive files, such as .tar
, .bz2
, .xz
, etc. by using the appropriate options. For example, to extract a .bz2
archive, you would use the -j
option:
tar -xf archive.tar.bz2 -C /path/to/destination