How to untar an archive without the root folder, but keeping the full hierarchy inside it?
Sophia Terry
If I’ve got a .tar archive, and when I extract it, it gives me a single folder foo containing some more stuff, like this:
foo/ something.txt another.txt bar/ something-else.txtIs there a way I can modify the .tar command to “skip” the root folder (foo in this case) and just extract all the contents of that folder directly into my cwd like this:
something.txt
another.txt
bar/ something-else.txt 1 Answer
Easy. Just use --strip-components=1 on the archive like this:
tar -xf archive.tar --strip-components=1And as explained in the official tar man page:
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
With the logic being that if a path consists of foo/something.txt then the first “component” of that path would be foo/ so --strip-components=1 would effectively drop the foo/ from the path foo/something.txt.