If I execute touch $(date '+%F %T'), I expect one file whose filename comprises the date and time to be created; but instead two files are created: one whose name is the date, and the other whose name is the time:

$ touch $(date '+%F %T')
$ ls -1

Why is this, and how can I create a file named 2019-03-05 12:39:26 instead, without using an underscore instead of a space?

  • If you run date '+%F %T' you will see you have two strings. This is like calling touch 12:39:26 2019-03-05. – Freddy Mar 5 '19 at 12:52

Use double quotes:

touch "$(date '+%F %T')"


| improve this answer | |

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