How to Exclude Absolute Paths for Tar

How do I exclude absolute paths for tar?

If you want to remove the first n leading components of the file name, you need strip-components. So in your case, on extraction, do

tar xvf tarname.tar --strip-components=2

The man page has a list of tar's many options, including this one. Some earlier versions of tar use --strip-path for this operation instead.

Tar a directory, but don't store full absolute paths in the archive

tar -cjf site1.tar.bz2 -C /var/www/site1 .

In the above example, tar will change to directory /var/www/site1 before doing its thing because the option -C /var/www/site1 was given.

From man tar:

OTHER OPTIONS

-C, --directory DIR
change to directory DIR

Create absolute paths in tar

If you mean when you're extracting the files, you just extract the tar file to /

For example:

tar -C / -xvf myfile.tar

If you're trying to force the tarfile to extract to a specific location, no matter what the person extracting it specifies, you can't do that. You'd need to include it in some kind of package, such as a .deb or .rpm file.

Shell command to tar directory excluding certain files/folders

You can have multiple exclude options for tar so

$ tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz .

etc will work. Make sure to put --exclude before the source and destination items.

tar folder and exclude all subfolders, then tar to specific path

first, use find to find the files meeting your criteria:

find ~/Desktop -type f -maxdepth 1

then pipe it to tar, using -T ( or --files-from) to tell tar to get the list of files from stdin:

 find ~/Desktop -type f -maxdepth 1 | \
tar -T - cvf r.tar

Tar exclude hidden files but use relative paths?

I now used the workaround:

XZ_OPT=-9e tar --exclude='./old' --exclude='.*' -cJvf /Volumes/Foo/$(date +%Y%m%dT%H%M)_full.tar.xz * -g incremetal

Hope it helps someone else as well

Excluding directory when creating a .tar.gz file

Try removing the last / at the end of the directory path to exclude

tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp" 

File or directory doesn't exists on exclude option using tar

The reason is that you specified -f which must precede the tarfile name. So you could also try

tar -cv --exclude='./web/uploads' -f backup.tar .

as long as the exclude option precedes source and destination. See this for more options like

tar --exclude='./web/uploads' -cvf backup.tar .



Related Topics



Leave a reply



Submit