When using tar I always include -f in the parameters but I have no idea why.

I looked up the man and it said;

-f, --file [HOSTNAME:]F

use archive file or device F (default
"-", meaning stdin/stdout)

But to be honest I have no idea what that means. Can anyone shed any light on it?

3 Answers 3


The -f option tells tar that the next argument is the file name of the archive, or standard output if it is -.

  • Ah, cheers! I presumed that the file name would have to appear next anyway so this -f was doing something more special!
    – Toby
    Commented Aug 26, 2010 at 10:45
  • 7
    @Toby: I suspect this is for historical reasons. "tar" is short for "tape archive", and presumably the original versions didn't envision people using disk files for archives all that often. Commented Aug 27, 2010 at 21:10

Quite simple. If you omit the -f parameter, output is passed to stdout:

gammy@denice:/tmp/demo$ tar -c a b c
a0000644000175000017500000000000011435437117010223 0ustar  gammygammyb0000644000175000017500000000000011435437117010224 0ustar  gammygammyc0000644000175000017500000000000011435437117010225 0ustar  gammygammygammy@denice:/tmp/demo$ ls
a  b  c

...what a mess!

The -f-parameter (as you quoted) expects a filename (and optionally a hostname), hence the first argument after it is the output filename:

gammy@denice:/tmp/demo$ tar -cf output.tar a b c
gammy@denice:/tmp/demo$ ls
a  b  c  output.tar
  • 5
    > If you oppress the -f parameter, output is passed to stdout. This is true with GNU tar, but I remember that on Solaris the default was a tape device (/dev/rmt0 or something like this). Commented Aug 27, 2010 at 18:42
  • *omit (not "oppress") Commented Dec 15, 2019 at 15:19
  • 1
    Even GNU tar honours the no-longer-documented TAPE variable. For example, try TAPE=/tmp/tape.tar tar cv /etc/h* and then ls -l /tmp/tape.tar. Commented Dec 15, 2019 at 17:35

It lets you specify the file or device you're going to be working with. Either creating, updating or extracting things from it depending on other supplied flags. For example:

# Create a tar file with the contents of somepath/
tar -cvf filename.tar somepath/

# Extract the tar file.
tar -xvf filename.tar

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .