Cognitive Conga: a blog

Dancing the conceptual kerfuffle shuffle

Ratiocination, n. An instance of [reasoning]. Also: a conclusion arrived at by reasoning. Doubt the applicability of this at your peril leisure.

tar cannot stat

Wtf? you might reasonably exclaim, unless you’re used to using *nix (Linux, UNIX, etc) from the command line.

tar is a command for moving a file or files into a single archive file (or for reversing the operation). It can also apply compression/decompression algorithms, and perform various other neat tricks. It’s useful and ubiquitous. Unfortunately, it’s also quite sensitive.

Just now, I was using tar -cfz mytarfile.tar.gz mydirectory to archive a directory, and this returned the error, tar: mytarfile.tar.gz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
. Hmm, not good.

Easy to fix, though. The solution to the problem is this: I should have written, tar -czf mytarfile.tar.gz mydirectory. In other words, the z and the f get swapped in the options. This is because the f option is supposed to denote that what follows it is a file. So the first command I tried was looking for a file called mytarfile.tar.gz to add to an archive file called z. Since the mytarfile.tar.gz didn’t exist, tar couldn’t locate, or stat, the file. Hence the error.

Oh, what fun is to be had at the command line!

8 Responses to “tar cannot stat”

  1. Bletaverse says:

    Thanks! you saved my day! I searched many forums and found no good answer until this.

  2. Erik Hansen says:

    Thanks for this post! It helped me with an issue I was having. I was trying to use: tar -czfv but I guess tar didn’t like the “v”

  3. Neel says:

    Thanks heaps! I was trying to backup my htdocs and i ran into the same problem. This page was really helpful to fix it.. cheers.. :)

  4. T says:

    Thanks for posting this!

  5. Dan says:

    Thanks. Amazingly, GNU’s own manual flagrantly ignores this:

    http://www.gnu.org/software/tar/manual/tar.html#SEC127

    “Wtf?” I might reasonably exclaim to their face.

  6. Grr says:

    This is why I “cannot stat” the command line.

  7. Stephen says:

    Thanks!

    And Erik, the v needs to be before the f as well

  8. Shawn says:

    Ugh… some days. Thanks! This had me completely frazzled.

Leave a Reply

You can use Markdown syntax and Markdown Extra syntax in this box.