Ubuntu – Overwriting files when extracting from a tar archive

tar

I play OpenTTD. There are three versions available and I want to have all three; stable, testing and nightly. I downloaded and compiled the source code for all three with no problems. The issue is when I want to compile a new version. When I extract the tar.xz file into /usr/lib/games/openttd-trunk/ the old files aren't overwritten. Instead, a new directory is created called openttd-trunk-r26175.

Is there any way to extract the files from the archive directly into /usr/lib/games/openttd-trunk/? That way I can just simply make without having to ./configure every time.

EDIT: I don't think I made clear that the archive has the source files inside a single folder called openttd-trunk-r26175. What I want to do is extract all files from that folder, but not the folder itself.

Best Answer

See this answer.

If you archive has one top level folder you can use --strip-components 1, to remove first folder from full files path.

Finaly, this should do what you want:

tar xf openttd-trunk-r26175.tar -C /usr/lib/games/openttd-trunk/ --strip-components 1