Skipping the first directory in a .tar file

Submitted by Sam on 22 February, 2012 - 23:49

Lots of the compressed files I download come in the form "project-name-1.2.3.tar.gz", and contain a directory within them named in the same format, so when you untar it creates a directory like "project-name-1.2.3", with all of the project files below it. As most of the time I seem to be already working in a new directory where I want the file to untar, I don't want to have to bother about moving the contents up a level and then deleting the old directory. The tar switch --strip-components=1 addresses this problem by removing the first directory on extraction.

See man tar | grep strip-components .

Attribution Noncommercial Share Alike
This text, Skipping the first directory in a .tar file, by Sam Haskell is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike license.
Drupal theme by Kiwi Themes.