tar: strip that path

There are a couple of options of gnu Tar that can save you some time:

  • -C lets you change the directory before adding|extracting file from an archive
  • –strip-components=X lets you extract an archive stripping the heading path  until the Xth level

Ex.

# tar cf /tmp/opt_postfix.tar -C /opt etc/postfix # backup /opt/etc/postfix without prepending /opt to the archive

# tar tvf  /tmp/opt_postfix.tar # check the archive
etc/postfix
etc/postfix/main.cf
etc/postfix/master.cf

# tar xf  /tmp/opt_postfix.tar -C /opt2/etc2/ –strip-components=1 # unpack in another directory

Lascia un commento