What does the -f parameter do in the tar command

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?

Asked By: Toby

||

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
Answered By: signine

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

Answered By: ddeimeke

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
gammy@denice:/tmp/demo$ 

…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
gammy@denice:/tmp/demo$ 
Answered By: gamen
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.