~/Downloads/t1$ tar tf test.t 
~/Downloads/t1$ tar xf test.t 
~/Downloads/t1$ ls ~/Downloads/t2
ls: cannot access ’/home/a/Downloads/t2’: No such file or directory 

why did this happen? is this because I didn't put the pathname?

  • 2
    How about ls ~/Downloads/t1/home/a/Downloads/t2? – Kamil Maciorowski Oct 29 '20 at 21:36

Try ls home/a/Downloads/t2/ from the directory you extracted the tar archive in.

Note how in the tar t listing the paths don't have leading slashes, so they'll be taken relative to the current working directory when the archive is extracted, not relative to the filesystem root. Usually, that's what you'd want anyway, since extracting files from an archive to potentially anywhere could be rather dangerous.

Of course, when creating an archive, one often uses tar cf foo.tar t2, and not tar cf foo.tar /home/a/t2 to only store the relevant part of the paths.

But since you already have the longer paths in the archive, you could a) go to the root to extract it:

~$ cd /
/$ tar xf ~/Downloads/t1/test.t 

or use an option to have tar remove the unwanted parts, e.g. at least in GNU tar:

Strip NUMBER leading components from file names on extraction.

So, tar xf test.t --strip-components=3 should do.

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.