Extract files to another directory using tar command

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.

Also Read:  Slingshot Gravity Space Shooting Game

If you want to extract to a new directory, then create it using below command first.

mkdir /target/directory

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

That’s it.

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Leave a Reply