{"id":3843,"date":"2013-07-10T07:00:00","date_gmt":"2013-07-10T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/07\/10\/why-is-the-syntax-for-touching-a-file-from-the-command-prompt-so-strange\/"},"modified":"2013-07-10T07:00:00","modified_gmt":"2013-07-10T07:00:00","slug":"why-is-the-syntax-for-touching-a-file-from-the-command-prompt-so-strange","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130710-00\/?p=3843","title":{"rendered":"Why is the syntax for touching a file from the command prompt so strange?"},"content":{"rendered":"<p>\n<a HREF=\"http:\/\/support.microsoft.com\/kb\/69581\">\nThe magic incantation for updating the last-modified date on a\nfile<\/a>\nis\n<\/p>\n<pre>\nCOPY \/B FILE+,,\n<\/pre>\n<p>\nWhat strange syntax!\nWhat&#8217;s with the plus sign and the commas, anyway?\n<\/p>\n<p>\nThe formal syntax is the much more straightforward\n<\/p>\n<pre>\nCOPY \/B A+B+C+D\n<\/pre>\n<p>\nThis means to start with the file <code>A<\/code>,\nthen append the files <code>B<\/code>, <code>C<\/code>, and <code>D<\/code>,\ntreating them all as binary files.\n<\/p>\n<p>\nIf you omit the\n<code>B+C+D<\/code> part,\nthen you get\n<\/p>\n<pre>\nCOPY \/B A+\n<\/pre>\n<p>\nThis means\n&#8220;Start with A, then append nothing.&#8221;\nThe side effect is that the last-write time gets updated,\nbecause the command processor opens <code>A<\/code> for append,\nwrites nothing,\nthen closes the handle.\n<\/p>\n<p>\nThat syntax has worked since at least MS-DOS&nbsp;2.1\n(the earliest version I still have a virtual machine for).\n<\/p>\n<p>\nI dont know where the two-comma version came from,\nbut it most likely exploited a parsing glitch in\n<code>COMMAND.COM<\/code>,\nand somehow this variant gained traction and\nbecame the version everybody used\n(even though the other version is two keystrokes shorter).\nAs a result, this weird syntax has become grandfathered\nas a special-case in the <code>CMD.EXE<\/code> parser.\nHere&#8217;s some actual code from the part of\n<code>CMD.EXE<\/code> which parses the arguments to the\n<code>COPY<\/code> command:\n<\/p>\n<pre>\nif (parse_state == SEEN_TWO_COMMAS)\n    copy_mode = TOUCH;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The magic incantation for updating the last-modified date on a file is COPY \/B FILE+,, What strange syntax! What&#8217;s with the plus sign and the commas, anyway? The formal syntax is the much more straightforward COPY \/B A+B+C+D This means to start with the file A, then append the files B, C, and D, treating [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-3843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>The magic incantation for updating the last-modified date on a file is COPY \/B FILE+,, What strange syntax! What&#8217;s with the plus sign and the commas, anyway? The formal syntax is the much more straightforward COPY \/B A+B+C+D This means to start with the file A, then append the files B, C, and D, treating [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=3843"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=3843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}