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 ?

  • 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?
    – arensb
    Jun 13, 2016 at 13:55
  • by hard link I mean this gnu.org/software/tar/manual/html_node/hard-links.html
    – Vikram
    Jun 13, 2016 at 14:06
  • and I run the command in ruby which gives me the list then I show them on page.
    – Vikram
    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.
    – arensb
    Jun 13, 2016 at 14:14
  • error I am getting - can not hard link to xyz.file :no such file or directory
    – Vikram
    Jun 13, 2016 at 14:20

1 Answer 1


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

The problem happens when you try to extract just one file

$ mkdir Y
$ cd Y
$ tar xvf ../foo.tar 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.

Not the answer you're looking for? Browse other questions tagged .