FreeBSD Linux

Extract Tar Files to a Different Directory

Syntax

Typical Unix tar syntax:
tar -xf file.name.tar -C /path/to/directory

GNU/tar syntax:
tar xf file.tar -C /path/to/directory

tar xf file.tar --directory /path/to/directory

Example: Extract files to another directory

In this example, I’m extracting $HOME/etc.backup.tar file to a directory called /tmp/data. First, you have to create the directory manually, enter:

 
mkdir /tmp/data

To extract a tar archive $HOME/etc.backup.tar into a /tmp/data, enter:

 
tar -xf $HOME/etc.backup.tar -C /tmp/data

To see a progress pass the -v option:

 
tar -xvf $HOME/etc.backup.tar -C /tmp/data
 

You can extract specific files too use:
 
tar -xvf $HOME/etc.backup.tar file1 file2 file3 dir1 -C /tmp/data

To extract a foo.tar.gz (.tgz extension file) tarball to /tmp/bar, enter:

 
mkdir /tmp/bar
tar -zxvf foo.tar.gz -C /tmp/bar

To extract a foo.tar.bz2 (.tbz, .tbz2 & .tb2 extension file) tarball to /tmp/bar, enter:

 
mkdir /tmp/bar
tar -jxvf foo.tar.bz2  -C /tmp/bar

Related Articles

  • Redis install steps on FreeBSD

      Install redis FreeBSD port collection: $ cd /usr/ports/databases/redis/ && make install clean # or with portmaster $ portmaster databases/redis   ===>  CONFIGURATION NOTE:   To setup “redis” you need...
  • Get CPU Information

    You can use the dmesg utility to display the contents of the system message buffer when FreeBSD comes up. For accuracy I recommend querying /var/run/dmesg.boot file. Usually a snapshot of...
  • Disk Benchmarking Tools.

    One of the main bottlenecks in server slowness is the Disk IO. If the speed of your disks are slow, then the CPUs of your servers may be wasting their CPU...
  • Media tools installation Error/Fix

    While installing media tools like Neroacc, we might come across the following errors   ERROR: ====== /usr/ports/audio/linux-neroaaccodec]# make install clean ===>  Staging for linux-neroaaccodec-1.5.1 ===>   linux-neroaaccodec-1.5.1 depends on file: /compat/linux/etc/redhat-release...