What does the -f parameter do in the tar command

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


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$ 

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

Tags:

Tar