1

I am trying to get list of all files in tar folder show them all on a page with links to download files. On click on single files it will be downloaded. This all is working fine except the hard link files

command I use to extract single file is

tar --extract --file=abc.tar.xz abc.file

but if the file is hard link then it gives me error, is there a way to get hard link file ?

5
  • 2
    What does "show them all on a page" mean? Are you generating HTML from a tar file? What do you mean by a hard link? And what error are you getting? Commented Jun 13, 2016 at 13:55
  • by hard link I mean this gnu.org/software/tar/manual/html_node/hard-links.html Commented Jun 13, 2016 at 14:06
  • and I run the command in ruby which gives me the list then I show them on page. Commented Jun 13, 2016 at 14:07
  • 1
    You haven't said which command(s) you're running, or which error message(s) you're seeing. Commented Jun 13, 2016 at 14:14
  • error I am getting - can not hard link to xyz.file :no such file or directory Commented Jun 13, 2016 at 14:20

1 Answer 1

7

The problem is in how tar stores files. So, for example

$ echo hello > a
$ ln a b
$ tar cf foo.tar a b
$ tar tf foo.tar
a
b

The problem happens when you try to extract just one file

$ mkdir Y
$ cd Y
$ tar xvf ../foo.tar b
b
tar: b: Cannot hard link to `a': No such file or directory
tar: Exiting with failure status due to previous errors

What you need to do is look at the verbose content list shows

$ tar tvf foo.tar 
-rw-r--r-- sweh/sweh         6 2016-06-13 10:43 a
hrw-r--r-- sweh/sweh         0 2016-06-13 10:43 b link to a

Now you can see that "b" has zero length, has type "h" (first character) and is flagged as " link to ". This tells you the real file you need to extract.

In this case you may want to use the "O" option (send to stdout), so you'd end up doing tar Oxvf ../foo.tar a > b to create a file of the right name.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.