Tag Archives: directory

Strip first directory from tar

I was trying to find this the other day – how to extract a tar and strip the first directory off. For example, WordPress extracts to the wordpress/ base directory by default and that can be annoying because you then have to move the content to the right place and remove the wordpress directory.

But there is an answer and it comes in the form of an option to pass to tar:
--strip-components [number]

So instead of something like:
tar -xvf wordpress-3.0.4.tar.gz
cp -r wordpress/* .
rm -Rf wordpress

You can just do:
tar -xvf wordpress-3.0.4.tar.gz --strip-components 1

Thought that might be useful for others (it certainly is for me!)..