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 ?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.