Normally I use tar with either tar -cvzf to create or to tar -xvzf to extract. Both cases need -f to specify the file. I know sometimes I will supply -f from standard input or standard output, but I still need -f switch.

So is there any situation I do not specify -f ?

  • Will this work for you: tar xz < file ?
    – andrew.46
    Feb 28, 2019 at 6:16

2 Answers 2


You do not need -f when you use stdin/stdout.

You may for instance do tar -cv foo > foo.tar, which will create foo.tar.

This may also be used to pipe together commands. Say you want to create a 7z compressed tar file:

tar -cv foo/ | 7z a -si foo.tar.7z

or you can do remote backups easily

tar -cv foo/ | ssh user@example.org "cat > backup.tar"

The same may also be applied in reverse

ssh user@example.org "cat backup.tar" | tar -xv 

to extract the tar ball.

So yes, there's cases when you don't need or don't want the f switch.


You can hardcode the archive file

  $ export TAPE=archive-file

This is possible but not recommended

See manual

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.