Creating a tar archive from a file list AND removing the full path
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.txtIf 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?
11 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.txtExtract tarball
tar -xvf html.tgz --strip-path=3This strips three components from the output path, i.e. /var/www/website.
4