The backslashes do nothing.
The -
and +
characters do not need to be escaped, because they are not special in any way in the syntax of any shell.
$ set -o xtrace
$ date +%F-%T
+ date +%F-%T
2019-08-15-11:51:46
$ date \+%F\-%T
+ date +%F-%T
2019-08-15-11:51:50
As you can see in the above trace output, the command that gets executed by the shell is the same regardless of the backslashes. Note too that the trace output is only "debugging output" from the shell and that whatever commands it outputs generally are not suitable for shell input.
The +
introduces a date
format specification. And the -
is just a literal dash, part of the format specification (will be a dash in the output too).
The command date \+%F\-%T
is the same as date +%F-%T
. You will often also see the date format quoted, as in date +'%F-%T'
. This makes no difference here as the format is a single word, but in date +'%F %T'
it needs to be quoted to keep the shell from splitting the format on the space into two separate arguments to date
.
What does makes a difference is the %
characters. You would want to escape these if you use them in a crontab specification. See e.g. How can I execute `date` inside of a cron tab job?
The %
character was special in the syntax of the fish
shell prior to version 3.0 (for job expansions) but only when the first character of a word (so not here when after a +
). Similarly, in zsh
, a leading %
character is special in that a ?
following it is not taken as a glob operator (to allow things like kill %?cmd
without having to quote the ?
), but again that doesn't apply here.