Untar to a particular directory is Failing

Below are my system and tar details.

bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-40 sun4v sparc sun4v
bash-3.2$ which tar
/usr/bin/tar

I use this command to untar at the file at this location: /web/applications/configurations

tar -xvf bent.tar -C /web/applications/configurations

and

tar -xvf bent.tar --directory /web/applications/configurations

MAN page shows the following explaining

I wish to give the complete physical path to the directory location where I wish to untar.

echo $? shows the tar command as successful but nothing is extracted at the destination. Also the command completes promptly as though it did nothing.

Can you please suggest a solution ?

try tar -tvf bent.tar and see what's inside the tarball...

If this is a Solaris system then please try omitting the '-' from the command line, e.g.,

# tar xvf <whatever>

I'm just suspicious that the '-' is maybe confusing the OS somehow (or perhaps not). Just try it and see what happens and whether it complains.

No complaints after removing the '-' but same result ... nothing gets extracted at the given location.

Other suggestions please.

---------- Post updated at 10:17 AM ---------- Previous update was at 10:15 AM ----------

The tar ball has several files and folders .... It works when I don't specify the destination i.e. extract it at the same location.

Also

bash-3.2$ du -sh bent.tar
 228M   bent.tar

Other suggestions please.

So back to vgersh99's suggestion, let's list the archive to see if it contains what you expect:

# tar tvf bent.tar

Make a note of the path names listed and particularly whether they start with a '.' (dot - meaning a relative path)

The listing is too big to paste here ... but here is what it looks like.

bash-3.2$ tar -tvf bent.tar
drwxr-xr-x   0/0        0 Apr 18 00:28 2017 bent/
-rw-r--r--   0/0     5926 Jul 18 03:56 2017 bent/999/Center.xml
-rw-r--r--   0/0      758 Jul 18 03:56 2017 bent/999/Produc.xml
-rw-r--r--   0/0     2673 Jul 18 03:56 2017 bent/999/bent_logo.gif
-rw-r--r--   0/0    49598 Jul 18 03:56 2017 bent/999/documents/xyz_version.pdf
-rw-r--r--   0/0       25 Jul 18 03:56 2017 bent/999/roll/auto.jsp
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/002/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/002/LEGAL/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/003/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/003/LEGAL/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/007/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/007/LEGAL/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/021/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/021/LEGAL/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/021/documents/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/024/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/024/documents/
drwxr-xr-x   0/0        0 Mar 21 03:17 2017 bent/027/
drwxr-xr-x   0/0        0 Mar 21 03:17 2017 bent/027/documents/
drwxr-xr-x   0/0        0 Jul 18 03:56 2017 bent/028/
......
......
-rw-r--r--   0/0   104727 Jul 18 03:56 2017 bent/inquiry/Formar.xsl
-rw-r--r--   0/0     9105 Jul 18 03:56 2017 bent/inquiry/Trer.xsl
bash-3.2$

Can you please suggest now ?

tar -xvf bent.tar -C /web/applications/configurations
and the path /web/applications/configurations exists AND has the proper permissions?
Try untarring it under a diff directory - say /tmp

1 Like

File permissions is also not the issue here ....

I even tried extracting it to /tmp but its not working.

I can even make a video demonstration and share the link here if you would like ?

---------- Post updated at 11:44 AM ---------- Previous update was at 11:28 AM ----------

See this output. Not sure why is it failing.

bash-3.2$ tar -xvf bent.tar -C /tmp/
bash-3.2$ echo $?
0
bash-3.2$ ls -ltrd /tmp/bent
/tmp/bent: No such file or directory

I even tried

/usr/sbin/tar instead of /usr/bin/tar but it still does not work

Can you post the tar version? Is it GNU tar?

tar --version

Is that a SunOS VM on a Mac (as per your uname -a output)?

Does the target directory have enough space? (Maybe it's on a separate drive?)

Somehow it seems that the size of the tar file (228 MB) could be an issue, but don't know why or how.

Here is the information you requested.

bash-3.2$ df -k /tmp
Filesystem            kbytes    used   avail capacity  Mounted on
swap                 15585680 1294448 14291232     9%    /tmp
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-40 sun4v sparc sun4v
 bash-3.2$ tar --version
tar: s: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile]  [exclude-file...] {file | -I include-file | -C directory file}...

if size of the tar is the issue then why does copying the bent.tar to /tmp and then -> tar -xvf bent.tar work ??

What's the output of "tar --version"?

Edit: Ok, I see that it's not GNU tar; doesn't understand the long version of qualifiers.
I can test it on my Solaris VM later, but as of now I don't why copying the bent.tar to /tmp and the "tar -xvf bent.tar" work.

It works when I do not give the -C option.

See the output below:

bash-3.2$ cp bent.tar /tmp
bash-3.2$ cd /tmp
bash-3.2$ tar -xvf bent.tar
x bent, 0 bytes, 0 tape blocks
x bent/002, 0 bytes, 0 tape blocks
x bent/002/LEGAL, 0 bytes, 0 tape blocks
x bent/003, 0 bytes, 0 tape blocks

Any solution will be appreciated.

Out of sheer curiosity, reg. post#10: does it make sense to mount a swap file system to /tmp (where tar might store intermediate data)?

Tar version

bash-3.2$ which tar
/usr/bin/tar
bash-3.2$ strings /usr/bin/tar | grep -i version
tar:  file # %llu: (%s) UTF-8 conversion failed.
tar: conversion routines not available for current locale.
file # %llu: (%s) UTF-8 conversion failed.
tar:  file # %llu: (%s) UTF-8 conversion failed.
tar:  file # %llu: (%s) UTF-8 conversion failed.
tar:  file # %llu: (%s) UTF-8 conversion failed.
tar: file # %llu: UTF-8 conversion failed.
tar: conversion routines not available for current locale.
file (%s): UTF-8 conversion failed.
tar: file (%s): UTF-8 conversion failed.
tar: invalid character in UTF-8 conversion of '%s'
tar: invalid character in UTF-8 conversion of '%s'
tar: conversion to UTF-8 aborted for '%s'.
tar: invalid character in UTF-8 conversion of '%s'
tar: conversion to UTF-8 aborted for '%s'.
bash-3.2$ file /usr/bin/tar
/usr/bin/tar:   ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
bash-3.2$ tar --version
tar: s: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile]  [exclude-file...] {file | -I include-file | -C directory file}...

---------- Post updated at 12:52 PM ---------- Previous update was at 12:37 PM ----------

You mean copy and untaring the bent.tar inside /tmp and then moving it to the desired destination location ?

That will be the last option if -C looks like too difficult or a bug.

No, I mean it looks like you mounted the (a) swap file system on /tmp? If so, I'd be afraid this negatively influences all processes on the system.

1 Like

What would happen if you did this:-

cd /target/directory
tar -xvf /path/to/tarball

I think that mounting /tmp using swap space is the default way that Solaris works, so I don't think there is an issue there unless you either boot (because, as swap, it doesn't persist) or you fill it and you server cannot swap.

Robin

Yes, "swap" stands for "memory". For illustration

$ mount -v | awk '$3=="/tmp"'
swap on /tmp type tmpfs read/write/setuid/devices/xattr/size=4096m/dev=5740002 on Tue Apr 11 14:48:23 2017

The -C seems to work, as said in the man page (see post#1), only with "c" and "r" but not with "x".
But you can work around

tar -xvf bent.tar -C /web/applications/configurations

with a sub-shell

cat bent.tar | (chdir /web/applications/configurations && tar -xvf -)

The file - is stdin.
Or the other way round, give the path to the archive file

(cd /web/applications/configurations && tar -xvf /path/to/bent.tar)

where the only purpose of the subshell is to preserve the current directory in the main shell.

Do you know the history of this .tar file?

Was it created on this system? If so, using what command?

If 'gtar' is installed on your system I would definitely just try substituting 'gtar' instead of 'tar' on the command line(s) and see what happens.

Many times I've had 'gtar' read a tarball that 'tar' couldn't read (properly).

Just a thought.

Actually the problem is in the -C option of tar .

     -C directory file       Performs a chdir (see cd(1))  opera-
                             tion on directory and performs the c
                             (create) or r (replace) operation on
                             file.  ...

You are using eXtract which is not supported by the -C option. As far as I can see there is no equivalent option for extracting to a particular directory.

Andrew