Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Creating a tar archive from a file list AND removing the full path

Writer Sophia Terry

I'm trying to combine two options for creating a tar archive, but they don't work well together. I don't know what's the problem.

I use:

tar -C /var/www/website html -cvzf html.tgz -T /tmp/htmllist.txt

If I use only the -C option it creates a tar archive with only a relative path "./html/", but ALL the files inside that folder. I don't want this.

Then if I use only the -T option it creates a tar archive with only the required files, but the path is absolute "/var/www/website/html/whatever.html". I don't want this either.

I want a combination of the two, but somehow it doesn't work.

The folder structure is:

/var/www/website/html/
  • Lots of .html files

The /tmp/htmllist.txt folder contains lines like:

  • /var/www/website/html/file1.html
  • /var/www/website/html/file5.html
  • /var/www/website/html/file32.html

And so on.

How do I solve this problem?

1

1 Answer

Tar works the other way around when using -T. It archives the files including full path. If you don't want the path, strip it on extracting, for example,

Create tarball

tar -C /var/www/website html -cvzf html.tgz -T /tmp/htmllist.txt

Extract tarball

tar -xvf html.tgz --strip-path=3

This strips three components from the output path, i.e. /var/www/website.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy