8

I remember reading in an IBM PC-DOS manual, around 1988 maybe, that there was a special syntax of the COPY command : COPY A.TXT +,, which would simply update the file's last change date to now. This was equivalent to the touch command which was available on Unix or bundled with MS-DOS compilers such as Turbo C. I used it occasionally from then on.

Around 1993, a colleague needed to do a "touch" on a file, so I wanted to show off and used COPY SOMEFILE +,, ... and somehow it corrupted her file.

I have a vague memory of trying it again with a later version of MS-DOS, like 6.0, and it didn't function as a "touch".

Which versions of MS-DOS or PC-DOS supported this use of COPY? Is there a story on why they chose this weird syntax?

6
  • 3
    hwiegman.home.xs4all.nl/msdos/69581.htm contains some sort of list. Aldo the correct way to use the copy command for this.
    – UncleBod
    Dec 9, 2022 at 16:21
  • 2
    @UncleBod would you care to write an answer using the information there? The KB entry is also available on jeffpar.github.io/kbarchive/kb/069/Q69581 Dec 9, 2022 at 16:36
  • Beg pardon - I effectively wrote the answer @UncleBod was being asked to write, not having followed the given links. I can't help thinking that MS ought to have written an actual 'touch' program instead of a KB article to canonize the dodgy copy syntax. Dec 10, 2022 at 2:21
  • @another-dave The KB article contains a list of supported versions, so you might as well have included that. Dec 10, 2022 at 17:58
  • 1
    File corruption - or rather truncation - happens when you copy +,, a binary file that contains Ctrl-Z. If you include the /b option that shouldn't happen.
    – Zac67
    Dec 12, 2022 at 9:02

1 Answer 1

6

That syntax apparently works in Windows 10 'cmd.exe'. It is not some special update-the-timestamp syntax, it's just a degenerate case of the standard syntax.

'+' indicates concatenation, as in copy a+b c. The parsing appears to be sloppy, in that the absence of a filename to the right of the + is tolerated.

',' is an alternative argument separatator, copy a+b,c. The parser doesn't seem to worry about extra commas.

For some reason I don't grasp, in cmd at least, copy a+, b is detected as bad syntax, but copy a+,, b is not, and copies a to b. So this is the rationale for two commas in the original question.

Absence of a destination causes the source filename to be reused.

So, in sum, you're copying the file onto itself, but managing to thwart the simple check on whether the destination is the same as the source. Functionally, it does (more or less) copy SOURCE.

I suppose that cmd.exe got it from the DOS command prompt.


The KB article referenced by Stephen Kitt and in different form by Uncle Bod says that this syntax was supported from MS-DOS 3.1 onwards, up through MS-DOS 6.22, which was the last version to go by that name. The article is silent about whether it worked in the COMMAND.COM bundled with Windows 95, 98, ME, but there seems no reason why it would be removed.

I believe that the syntax was not invented for this particular purpose. It's just sloppy parsing.

4
  • It's not sloppiness. An append operation with a list of just one file has different semantics to a copy operation with one source file. Text mode becomes the default (instead of binary), search wildcards result in multiple output files (instead of one combined file), and the destination file is not truncated if it is also the first file in the list of files to combine (whereas a copy operation truncates). Moreover: this syntax goes all of the way back to MS-DOS 1.1, having an obvious predecessor in the syntax of DEC's pip utility, which also had an append syntax.
    – JdeBP
    Dec 11, 2022 at 5:39
  • 1
    Note that the KB article recomends usign the /B switch so that a ^Z in the file doesn't mess things up. In a C source file that shouldn't be a problem, but you never know.
    – UncleBod
    Dec 11, 2022 at 10:42
  • @JdeBP - no such thing as 'the' pip syntax, since DEC implemented something called 'pip' on practically every OS they wrote (and there were many). In RSX-11M, the syntax was out = in /AP, i.e. there was a specific 'append' command, expressed in the peculiar CSI way. Maybe you refer to TOPS-10? Dec 11, 2022 at 19:45
  • 1
    @UncleBod Yes, this is probably what happened when I tried to impress my colleague, it must have been a binary file and I didn't know the /B was needed.
    – Nimloth
    Dec 12, 2022 at 1:35

You must log in to answer this question.

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