I'm trying to tar and gzip a file with date and time as the name:

date=$(date '+%d-%m-%Y_%H:%M:%S');    
tar -zcf "$date".tar.gz repo/bin/

But I get back:

tar (child): Cannot connect to 17-08-2017_21: resolve failed
tar: Child returned status 128
tar: Error is not recoverable: exiting now

What exactly is happening here and how can I fix?

Is tar trying to connect to the name as if it's an ip?

  • 7
    The ISO standard for dates is yyyy-mm-ddThh:mm:ss, or +%FT%T in date's syntax. In addition to giving the date in an unambiguous format, it sorts nicely!
    – user4443
    Aug 18, 2017 at 5:37
  • @drewbenn with GNU date, also: date --iso-8601=s (but it also adds a timezone offset)
    – muru
    Aug 18, 2017 at 6:57
  • 2
    I would discourage from using colons. Something like 20170818_122314 or similar is sufficiently easy to recognize and/or parse. Colons cause trouble in various situations (you just discovered one).
    – Rolf
    Aug 24, 2017 at 7:31

1 Answer 1


Yes it is. At least for GNU tar, the documentation says:

If the archive file name includes a colon (:), then it is assumed to be a file on another machine. If the archive file is user@host:file, then file is used on the host host. The remote host is accessed using the rsh program, with a username of user. If the username is omitted (along with the @ sign), then your user name will be used. (This is the normal rsh behavior.).

It also provides a work-around:

      Archive file is local even if it has a colon.
  • 6
    Shorter workaround: tar zcf ./"$date".tar.gz ... The leading path specification seems to make tar treat it as a regular file
    – muru
    Aug 18, 2017 at 6:17

You must log in to answer this question.

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