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:


Is 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:


1 Answer 1


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

  • 3
    I'd advise only using this for tar files that you know the structure of. Note that --strip-components will not just strip leading directories, if you had a tar file that didn't have a directory as its top level entry (e.g., if the contents of the tar file were [file1.txt, somedirectory/] this command would not extract file1.txt. I haven't found a method that only strips a top level directory without causing problems with other kinds of tar files that just have plain files as their top level entry.
    – jrh
    Apr 28, 2020 at 15:33
  • 1
    Wouldn't have thought tar would work with zip files, but it did.
    – C1pher
    Jun 30 at 18:15

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.