You can use two different methods to exclude files from a tarball using GNU tar:
1. Use the –exclude option like the example below:
# tar -cvf /tmp/backup.tar –exclude=’tmp’ –exclude=’temp’ /data
2. Use the -X flag and create a file list:
# tar -cvf /tmp/backup.tar -X /tmp/exclude_list /data
# cat /tmp/exclude_list
tmp
temp
Both methods will exclude the files or directories /data/tmp and /data/temp from the tar archive. To confirm, you can run
tar -tf /tmp/backup.tar
and confirm that the excluded files are not in the tarball.