Occasionally I need to extract a source tarball to a subdirectory without its leading path directory and every time I need it I forget the necessary GNU tar switches, so here is todays lesson in the two tar switches required.

tar --strip-components 1 -xvf package_1.1.tar.bz2 -C package

“–strip-components 1″ will strip off the first (1) folder of the archives path. Replacing 1 with 2 will do the obvious and strip off 2 folders/preceding path components.

“-C package” is nice and simple, it will extract the archive into the folder package. You could be fancy and do “-C ~/source/package” and extract the archive anywhere you fancy.

© 2012 Linux Sand Garden Suffusion theme by Sayontan Sinha