windows server 2008 - copy /a, copy /b - use of this options

07
2014-07
  • erch

    On Microsof Windows Server 2008 (R1), 32-Bit, I have some trouble understanding the use of as well as the difference between

    copy /a and copy /b

    The Technet Article on copy doesn't help me much:

    copy /a → … copy an ASCII text file that uses an end-of-file character (that is, CTRL+Z) to indicate the end of the file. … The effect of /a depends on its position in the command-line string. When /a follows Source, copy treats the file as an ASCII file and copies data that precedes the first end-of-file character.

    copy /b directs the command interpreter to read the number of bytes specified by the file size in the directory. /b is the default value for copy, unless copy combines files. … The effect of /b depends on its position in the commandline string. When /b follows Source, copy copies the entire file, including any end-of-file character. → source

    This is quite confusing for me, as I thought that copy simply clones a file to another destination.

    Question: An actual example where copy /a and⁄or copy /b would make a difference would help me greatly in understanding the difference.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    Is there a way to append files efficiently using the DOS copy command?
  • clsturgeon

    Using the DOS copy command syntax to concatenate files:

    copy file1.txt+file2.txt all.txt
    

    I know I can do this...

    copy file1.txt+file2.txt file1.txt
    

    Is this efficient? Is it doing what I'm expecting? It works, but I want to know is it actually appending to file1.txt or is it copying file1.txt (bad), concatenating file2 and then renaming to file1.txt (which is not efficient)?


  • Related Answers
  • Tyler

    copy is copying file1.txt and file2.txt into memory, concatenating them then writing out to file1.txt. It's not copying to a new file then renaming that file so really there's not much extra disk I/O.

    You can also use type.

    type file2.txt >> file1.txt
    

    The >> operator appends text. But that will, of course, not work for binary files.

  • Synetech

    Is this efficient?

    Sure. However, using the the /b switch can/may increase performance by simply concatenating the bytes instead of processing the files as text. This is particularly noticeable when concatenating very large text files.

    Is it doing what I'm expecting?

    Usually yes, but if the file was made in Linux, Mac, or other system with differing file-/line-terminators, then it may give unexpected results. It is a good idea to use the /b switch in general, even for text files.

    I want to know is it actually appending to file1.txt or is it copying file1.txt (bad), concatenating file2 and then renaming to file1.txt (which is not efficient)?

    Yes, it is creating a new, temporary file, deleting the original, and renaming the temp file to the original name, but deleting and renaming take no time and unless the original file is massive, you won’t normally notice even the (redundant) copying of the original file.