I'm trying to create tar.gz file using the following command:

sudo tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/

It then start to create files (many files in folder), but then I get the following error:

tar: dvr_rdk_v1.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

I don't see any description of this error, what does it mean?

5 Answers 5


Remove - from vcfz options. tar does not need hyphen for options.

With a hyphen, the argument for the -f option is z. So the command is in effect trying to archive dvr_rdk_v1.tar.gz and dvr_rdk into an archive called z. Without the hyphen, the semantics of the options changes, so that the next argument on the command line, i.e. your archive's filename, becomes the argument to the f flag.

Also check your write permission to the directory from which you are executing the command.

  • 7
    It doesn't need hyphens, but they shouldn't be a problem, they're just optional Aug 10, 2014 at 19:00
  • 25
    @MichaelMrozek Actually, removing the - does make a difference, because GNU tar is quirky. Option arguments can't be bundled in the first argument when it doesn't start with a -, so the argument to f is the next argument to tar, and so tar vcfz dvr_rdk_v1.tar.gz is equivalent to tar -v -c -f dvr_rdk_v1.tar.gz -z. Aug 10, 2014 at 22:19
  • 1
    I also realized if I remove the z or j the archive compression is successful even with - involved. When I add the hyphen is included it treats the last character in the option as a "file". So as a result I get j or z as an archived file if I use this option -cvfz or -cvfj.
    – JohnnyQ
    Sep 14, 2016 at 2:11
  • 23
    Summary: if 'f' occurs as an option anywhere other as than the last option, then the command will not do what was intended. I don't see how Gnu couldn't add a warning when they detect such a serious and easily-detectable issue. I just spent 40min trying to debug this weirdness. This one must have wasted hundreds of thousands of man-hours of productivity.
    – smci
    Oct 25, 2017 at 1:14
  • I had to remove the hyphen to make it work, although I have used the hyphen many times on other systems. Can't they just keep the syntax consistent??!
    – Stonecraft
    Jan 31, 2020 at 3:04

The -f option should directly precede the filename. So, use tar -vczf filename.tar.gz instead of -vcfz

  • 3
    Ah this explains why the command I'm using tries to create a compressed archive file called j or z with these commands -cvfj and -cvfz respectively.
    – JohnnyQ
    Sep 14, 2016 at 2:14
  • 1
    This is the answer
    – Sohail Si
    May 5, 2022 at 17:01

The tar command historically has been one of the few commands that doesn't follow the Unix utility syntax guidelines.

The standards page for tar says:

Use the first file operand (or the second, if b has already been specified) as the name of the archive instead of the system-dependent default

While the syntax guidelines include this:

Guideline 5:
One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.

So while the command you typed, tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/, would be fine on older versions of tar, certain versions of tar that are written to strictly follow the utility syntax guidelines will parse this to mean "use z as the file argument to -f". So you should use the following to be portable:

tar -cvzf dvr_rdk_v1.tar.gz dvr_rdk/

Notice that the -f needs to go immediately before the archive name but after the --exclude options in this Makefile multi-line example...

-f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'  

#Backup $HOME/.bitcoin - Makefile usage example

TIME=$(shell date +%s)  
export TIME  
    @echo ''  
    bash -c 'mkdir -p $(HOME)/.bitcoin'  
    bash -c 'conf/get_size.sh'  
    bash -c 'tar czv --exclude=*.log --exclude=banlist.dat \  
            --exclude=fee_exstimates.dat --exclude=mempool.dat \  
            --exclude=peers.dat --exclude=.cookie \  
            --exclude=.lock --exclude=.walletlock \  
            -f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'  
    #install current bitcoin.conf  
    bash -c 'install -v conf/bitcoin.conf $(HOME)/.bitcoin'  
    @echo ''  

For future readers, this post was the answer for me. Keep wildcards outside the quotes: tar -zcf archive.tar.gz "file-0"*

You must log in to answer this question.

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