Tuesday, November 9, 2010

Strip leading path with GNU tar

Sometimes, when I untar an archive file, I need to strip leading path from the archived files. For example, if my archive is stored on a DVD disk the following command would unpack it to my home directory and strip the leading path name:

shell> cd $HOME
shell> tar --extract --file /mount/Backups/home-bkp-11082010.tar.gz --strip-components=1 

Essentially, if my original backup had a  file vlg/foobar.txt, the vlg/ part of the path would be stripped out.

This comes very handy if the backup file was created with something like:

shell> cd /home
shell> sudo tar xvfz home-bkp-11082010.tar.gz vlg

No comments:

Post a Comment