Tar or Tape archiver is an archiving program. Using tar, you can create, extract and manage archive file. An archive file is a compressed file that contains one or more files together.
To extract an archive to a directory different from the current, you use the -C, or –directory, tar option. If the target directory already exist, then below is the syntax for that command.
tar -xf archive.tar -C /target/directory
Here “archive.tar” is the file name and /target/directory is the path. You can replace these values based on yours.
If you want to extract to a new directory, then create it using below command first.
After that run above tar command.
If your tar archive file already contains a directory name you want to change, then add the –strip-components=1 option in your command like below.
tar -xf archive.tar -C /target/directory --strip-components=1