DISQUS

Tech-Recipes: Create a TAR archive of a directory | UNIX | Tech-Recipes

  • grinch · 5 years ago
    The example should be tar -cf archive.tar * (note the hyphen)
  • qmchenry · 5 years ago
    It may look funny without it, but the hyphen is optional. The traditional syntax for tar does not use the hyphen for command line options that we've become used to using. Likewise, the GNU double hyphen options are a relatively new addition to UNIX.

    For example, here is an excerpt from the Solaris 9 man page for tar:
    tar c [ bBeEfFhiklnopPqvwX@ [0-7]] [block] [tarfile]
    [exclude-file] {-I include-file | -C directory | file |
    file} ...

    I don't know when the hyphen options were implemented in tar, but I suspect that there are still versions of tar that would gag on a -cf. The hyphenless syntax should work everywhere.
  • coredump · 4 years ago
    NAME
    tar - The GNU version of the tar archiving utility

    SYNOPSIS
    tar [ - ] A --catenate --concatenate | c --create | d --diff --compare | r --append | t --list | u
    --update | x -extract --get [ --atime-preserve ] [ -b, --block-size N ] [ -B, --read-full-blocks ] [ -C,
    --directory DIR ] [ --checkpoint ] [ -f, --file [HOSTNAME:]F ] [ --force-local ] [ -F, --info-script
    F --new-volume-script F ] [ -G, --incremental ] [ -g, --listed-incremental F ] [ -h, --dereference ] [
    -i, --ignore-zeros ] [ -j, -I, --bzip ] [ --ignore-failed-read ] [ -k, --keep-old-files ] [ -K, --start-
    ing-file F ] [ -l, --one-file-system ] [ -L, --tape-length N ] [ -m, --modification-time ] [ -M, --multi-
    volume ] [ -N, --after-date DATE, --newer DATE ] [ -o, --old-archive, --portability ] [ -O, --to-stdout ]
    [ -p, --same-permissions, --preserve-permissions ] [ -P, --absolute-paths ] [ --preserve ] [ -R,
    --record-number ] [ --remove-files ] [ -s, --same-order, --preserve-order ] [ --same-owner ] [ -S,
    --sparse ] [ -T, --files-from=F ] [ --null ] [ --totals ] [ -v, --verbose ] [ -V, --label NAME ] [
    --version ] [ -w, --interactive, --confirmation ] [ -W, --verify ] [ --exclude FILE ] [ -X,
    --exclude-from FILE ] [ -Z, --compress, --uncompress ] [ -z, --gzip, --ungzip ] [ --use-compress-
    program PROG ] [ --block-compress ] [ -[0-7][lmh] ]

    filename1 [ filename2, ... filenameN ]

    directory1 [ directory2, ...directoryN ]
  • qmchenry · 4 years ago
    Yeah, even with GNU tar, the hyphen is optional as indicated by the square brackets around the hyphen like [ - ] .. there are so many scripts and old timers like me around who user tar with the old hyphenless syntax that it would be miserable if it didn't work anymore.
  • Guest · 4 years ago
    How to tar a folder which contains list subfolders in unix.Please get back to me immediately<font color="red"></font>
  • dan · 4 months ago
    Thanks for saving my time with this posting.