Home / Solaris 10 / How to concatenate two tar files in Solaris

How to concatenate two tar files in Solaris

TAR binary is used to combine multiple files in to single archive with extension of “.tar” file.But using Solaris in-built tar utility, you can not combine two previously created tar files.If you want combine tar file then you have to install GNU-TAR binary.

This concatenate feature is available in GNU tar which is freely available in sunfreeware 
website.
Experiment :

Here i am trying to concatenate two tar files using solaris inbuilt tar.Let see what happens.
Ex:My two directories are dirtar & test2
bash-3.00# cd dirtar/
bash-3.00# ls -lrt
total 6
-rw-r--r-- 1 root root 0 Jul 17 13:51 9
-rw-r--r-- 1 root root 0 Jul 17 13:51 8
-rw-r--r-- 1 root root 0 Jul 17 13:51 7
-rw-r--r-- 1 root root 0 Jul 17 13:51 0
-rw-r--r-- 1 root root 0 Jul 17 14:37 lingesh
-rw-r--r-- 1 root root 0 Jul 17 14:37 raj
bash-3.00# cd /test2/
bash-3.00# ls -lrt
total 6
-rw-r--r-- 1 root root 0 Jul 17 02:19 1
-rw-r--r-- 1 root root 0 Jul 17 02:19 2
-rw-r--r-- 1 root root 0 Jul 17 02:19 3
-rw-r--r-- 1 root root 0 Jul 17 02:19 4
-rw-r--r-- 1 root root 0 Jul 17 02:19 5
-rw-r--r-- 1 root root 0 Jul 17 02:19 6
Here i am creating the tar using the Solaris inbuilt tar executable .
bash-3.00# tar cvf test2.tar test2
a test2/ 0K
a test2/vindo 0K
a test2/4 0K
a test2/3 0K
a test2/dileep 0K
a test2/2 0K
a test2/5 0K
a test2/1 0K
a test2/6 0K
bash-3.00# tar cvf dirtar.tar dirtar
a dirtar/ 0K
a dirtar/raj 0K
a dirtar/8 0K
a dirtar/lingesh 0K
a dirtar/9 0K
a dirtar/0 0K
a dirtar/7 0K
bash-3.00# ls -lrt |tail
drwxr-xr-x 19 root sys 19 Jul 17 14:24 opt
drwxr-xr-x 3 root root 8 Jul 17 14:29 Desktop
drwxr-xr-x 21 root sys 310 Jul 17 14:30 dev
drwxr-xr-x 2 root root 8 Jul 17 14:37 dirtar
drwxr-xr-x 2 root root 10 Jul 17 14:38 test2
drwxrwxrwt 12 root sys 1265 Jul 17 14:40 tmp
-rw-r--r-- 1 root root 5632 Jul 17 14:44 test2.tar
-rw-r--r-- 1 root root 4608 Jul 17 14:44 dirtar.tar

When you try to concatenate those two tar files , you will get  below error.

bash-3.00# tar --concatenate --file=dirtar.tar test2.tar
tar: a: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile] [size] [exclude-file...] {file | -I include-file | -C directory file}...
bash-3.00# which tar
/usr/sbin/tar
bash-3.00# file /usr/sbin/tar
/usr/sbin/tar: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, stripped

To fix this issue,

Installation Steps:
1.Install the Dependencies 
2.Install GNU tar

Dependencies:(downloaded from sunfreeware)
bash-3.00# pwd
/Desktop
-rwxrw-rw- 1 root root 2633216 Jul 17 14:26 libiconv-1.14-sol10-x86-local
-rw-r--r-- 1 root root 141824 Jul 17 14:26 libintl-3.4.0-sol10-x86-local
-rwxrw-rw- 1 root root 1862656 Jul 17 14:29 libgcc-3.4.6-sol10-x86-local
-rwx------ 1 root root 4746752 Jul 17 14:13 tar-1.26-sol10-x86-local
To install the package ,
# pkgadd -d /Desktop/file_name
Repeat the above command for all the packages.

By default, It will be installed in /usr/local/bin.
To verify the GNU tar,
bash-3.00# ldd /usr/local/bin/tar
libintl.so.8 => /usr/local/lib/libintl.so.8
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libsec.so.1 => /usr/lib/libsec.so.1
libc.so.1 => /usr/lib/libc.so.1
librt.so.1 => /usr/lib/librt.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libavl.so.1 => /lib/libavl.so.1
libaio.so.1 => /lib/libaio.so.1
libmd.so.1 => /lib/libmd.so.1
libmp.so.2 => /lib/libmp.so.2
libscf.so.1 => /lib/libscf.so.1
libdoor.so.1 => /lib/libdoor.so.1
libuutil.so.1 => /lib/libuutil.so.1
libgen.so.1 => /lib/libgen.so.1
libm.so.2 => /lib/libm.so.2
If you are missing any libraries ,install it.
Now we can test the concatenate using the GNU tar.
bash-3.00# /usr/local/bin/tar tvf test2.tar
drwxr-xr-x root/root 0 2012-07-17 14:38 test2/
-rw-r--r-- root/root 0 2012-07-17 14:38 test2/vindo
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/4
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/3
-rw-r--r-- root/root 0 2012-07-17 14:38 test2/dileep
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/2
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/5
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/1
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/6
bash-3.00# /usr/local/bin/tar tvf dirtar.tar (file created by inbuilt tar)
drwxr-xr-x root/root 0 2012-07-17 14:37 dirtar/
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/raj
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/8
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/lingesh
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/9
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/0
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/7
Here i am just listing the tar contents (file created by inbuilt tar)
using the GNU tar , i am  merging to two tar files
bash-3.00# /usr/local/bin/tar --concatenate --file=dirtar.tar test2.tar
bash-3.00# /usr/local/bin/tar tvf dirtar.tar
drwxr-xr-x root/root 0 2012-07-17 14:37 dirtar/
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/raj
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/8
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/lingesh
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/9
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/0
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/7
drwxr-xr-x root/root 0 2012-07-17 14:38 test2/
-rw-r--r-- root/root 0 2012-07-17 14:38 test2/vindo
/usr/local/bin/tar: A lone zero block at 10

But still we didn’t get what we need it.The ground rule is tar files also need to be created by GNU tar  to merge multiple tar files. 


Now i am removing the tar files which are created by in-built tar binary .
bash-3.00# rm dirtar.tar test2.tar
I am creating the tar files using the GNU tar.
bash-3.00# /usr/local/bin/tar cvf dirtar.tar dirtar
dirtar/
dirtar/raj
dirtar/8
dirtar/lingesh
dirtar/9
dirtar/0
dirtar/7
bash-3.00# /usr/local/bin/tar cvf test2.tar test2
test2/
test2/vindo
test2/4
test2/3
test2/dileep
test2/2
test2/5
test2/1
test2/6

Merging two tar files using the GNU tar

bash-3.00# /usr/local/bin/tar --concatenate --file=dirtar.tar test2.tar
Now the result is what we desired . So the bottom line is , we have to use GNU tar for creating tar files and merging both.
bash-3.00# /usr/local/bin/tar tvf dirtar.tar
drwxr-xr-x root/root 0 2012-07-17 14:37 dirtar/
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/raj
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/8
-rw-r--r-- root/root 0 2012-07-17 14:37 dirtar/lingesh
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/9
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/0
-rw-r--r-- root/root 0 2012-07-17 13:51 dirtar/7
drwxr-xr-x root/root 0 2012-07-17 14:38 test2/
-rw-r--r-- root/root 0 2012-07-17 14:38 test2/vindo
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/4
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/3
-rw-r--r-- root/root 0 2012-07-17 14:38 test2/dileep
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/2
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/5
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/1
-rw-r--r-- root/root 0 2012-07-17 02:19 test2/6
Hopes this will help you….

Thank you for reading this article.Please leave a comment if you have any doubt ,i will get back to you as soon as possible.
VMTURBO-CLOUD-CAPACITY

One comment

  1. As I am new to linux, could you please explain about linux realtime architecture?

    like what are the servers(infrastructure servers) and services running and what is the dairly work of a linux system admin?

Leave a Reply

Your email address will not be published. Required fields are marked *