User Tools

Site Tools


compression_tar

If you want to send us your comments, please do so. Thanks
More on comments


tar

$ tar --version
tar (GNU tar) 1.30\\

Warning: tar does not know about globbing

Comments

Comments (starting with a #) are not allowed on the tar command line nor on the broken (with \) command line. If added, an error will occur

Globbing

See man glob
See Globbing

When creating an archive wildcards are not allowed, will not work. --create, --list
Although it seems to work with the --exclude=PATTERN option with a glob(3)-style wildcard pattern (not tested by us. We did not find man 3 glob. We found man 7 glob)
Globbing does not work for the inclusion of files directly nor with --files-from=FILE
tar only supports wildcards when working with tar archive: --extract

Create

--create
tar --create --file ~/file.tar /directory/
tar --preserve-permissions --create --bzip2 --file /tmp/root.tar.bz2 . # Do not forget the dot ( . )! This also includes hidden files and directories in the current directory

Deletes an existing tar file of the same name and creates a new one

Update

New and newer files are copied / overwritten into the tar file

--update

Update the tar file file.tar containing the contents of /directory/. If file.tar does not exist is will be created

tar --update --file ~/file.tar /directory/

Deletes, in the tar file, non existent source files form the tar file

Include files from a file

tar can include files read from a list of files in a file FILE (any name)

--files-from=FILE

In FILE use / do

  • Absolute path. Like /home/user/somefile.txt
  • One entry per line
  • No ''' (quotes) around an entry: /home/user/somefile.txt

Example file contents. No spaces in front or after the entry

/home/user/somefile1.txt
/home/user/somefile2.txt
/home/user/somefile3.txt
/home/user/somefile4.txt

Maybe the --verbatim-files-from option can be useful

Globbing

tar has no globbing build in. The globbing is done by the shell
When creating an inclusion file with an echo command globing does not work

echo -e '/usr/share/themes/ZOMG-PONIES!\n/usr/share/themes/My*' > tarincludelist.txt 

It results in an error

tar: /usr/share/themes/My.*: Warning: Cannot stat: No such file or directory

This does work

echo -e "/usr/share/themes/ZOMG-PONIES!\n/usr/share/themes/My.Adwaita-dark\nMy.Notifier2" > tarincludelist.txt 

because globbing is not used
An alternative (the 1 in -1d is a number one):

ls -1d /usr/share/themes/ZOMG-PONIES!\n/usr/share/themes/My.* > tarincludelist.txt

This is universal solution since also all in the future created My.* directories will be incorporated

Exclude directories

Depending on the tar version --exclude entries might have to be the first in the command

You can not exclude a top level directory in the tree you are in. This does not work

rsync --exclude=aa aa/ bb/ cc

does not exclude aa/

Do not specify files within a directory. Only specify the directory

rsync --exclude=aa/subdir aa/ bb/

This does not work

rsync --exclude=aa/subdir/* aa/ bb/

Exclude form a file

See also tar and rsync file exclusion

--exclude-from=FILE

Watch out for tailing spaces since they count as part of the file or directory name!

Comments

In the exclude file FILE comments, lines starting with a #, are not allowed
Empty lines are allowed

List

These all list the contents of the container. They are all the same

tar --list --file file.tar.bz2
tar --list -f file.tar.bz2
tar -tf file.tar.bz2
tar tf file.tar.bz2

Because tar does not know about globbing this

tar --list --file=*.tar | less -S

does not work. Use

for i in $(ls -1 *.tar); do tar --list --file=$i; done | less -S

Extract

Extract some files from a file container

tar --extract --wildcards --file filename.tar.bz2 *partoffilenamein_tar.bz2_file*

Extract all files from file.tar.xz in /opt

tar --extract --file $HOME/downloads/file.tar.xz --directory=/opt
tar xf $HOME/downloads/file.tar.xz --directory=/opt

Extract files listed in the file filestoextract.txt (use the full pad as in the archive
Check with tar --list filename.tar.bz2 | less

tar --extract --file filename.tar.bz2 --files-from=filestoextract.txt

Add v or --verbose for verbose output

Errors

Removing leading /

tar: Removing leading `/' from member names

Use the -P, --absolute-names option which makes that leading slashes from file names when creating archives are not striped. This did partially solve the issue for us

  • The leading / is present
  • The error message is incorporated in the tar file

If --absolute-names is omitted

  • No leading /
  • The error message is not incorporated in the tar file

This seems to be a bug or we do not understand something

The reason for striping the leading slash is found in the fact that archives with absolute locations are a security risk. Attackers could use such archives to trick users into installing files in critical system locations

Only zero's

tar creates a file containing only zero's Solution: t.b.d.


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
compression_tar.txt · Last modified: 19-08-2023 20:02 by wim