The Computer Oracle

How to untar an archive without the root folder, but keeping the full hierarchy inside it?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Horror Game Menu Looping

--

Chapters
00:00 How To Untar An Archive Without The Root Folder, But Keeping The Full Hierarchy Inside It?
00:32 Accepted Answer Score 129
01:02 Thank you

--

Full question
https://superuser.com/questions/899684/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#commandline #tar

#avk47



ACCEPTED ANSWER

Score 129


Easy. Just use --strip-components=1 on the archive like this:

tar -xf archive.tar --strip-components=1

And 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.