Difference between revisions of "tar notes"

From Noah.org
Jump to navigationJump to search
m
Line 21: Line 21:
 
tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='ttyout=Wrote %u%  \r' -zxf tarball.tgz
 
tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='ttyout=Wrote %u%  \r' -zxf tarball.tgz
 
</pre>
 
</pre>
 +
 +
This is a little easier to read as a shell function:
 +
<pre>
 +
untar_progress ()
 +
{
 +
    TARBALL=$1;
 +
    BLOCKING_FACTOR=$(($(gzip --list -v ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1));
 +
    tar --blocking-factor=${BLOCKING_FACTOR} --checkpoint=1 --checkpoint-action='ttyout=Wrote %u%  \r' -zxf ${TARBALL}
 +
}
 +
</pre>
 +
 
If you prefer the have the update message on a separate line then use this syntax:
 
If you prefer the have the update message on a separate line then use this syntax:
 
<pre>
 
<pre>
 
tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='echo=Wrote %u%' -zxf tarball.tgz
 
tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='echo=Wrote %u%' -zxf tarball.tgz
 
</pre>
 
</pre>

Revision as of 01:47, 24 August 2010


permission and ownership of files inside a tar

If you are making tarballs for installing on other machines you usually want the files inside the archive to be owned by root. Usually you do not build as root. You can force ownership and group with three arguments. This will record the UID and GID in the tar file as 0 (root).

tar --numeric-owner --owner=0 --group=0 -czf install_tree.tgz $STAGING_DIR

This is a fancier version that sets input and directories; trims the trailing slash off of STAGING_DIR; and sets the gzip compression level to the max.

GZIP="--best" tar --numeric-owner --owner=0 --group=0 --directory=${STAGING_DIR%/*} --exclude=.svn -czf ${OUTPUT_DIR##*/}/piebox_setup.tar.gz ${STAGING_DIR##*/}

show progress bar when decompressing tar

This will print and update message like "Wrote 27%". This will overwrite and update the current line.

tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='ttyout=Wrote %u%  \r' -zxf tarball.tgz

This is a little easier to read as a shell function:

untar_progress () 
{ 
    TARBALL=$1;
    BLOCKING_FACTOR=$(($(gzip --list -v ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1));
    tar --blocking-factor=${BLOCKING_FACTOR} --checkpoint=1 --checkpoint-action='ttyout=Wrote %u%  \r' -zxf ${TARBALL}
}

If you prefer the have the update message on a separate line then use this syntax:

tar --blocking-factor=$(($(gzip --list -v tarball.tgz | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1)) --checkpoint=1 --checkpoint-action='echo=Wrote %u%' -zxf tarball.tgz