Overview
There are some commands for combining files such as copy
and cat
. Respectively, copy
is a command for Windows prompt and cat
is a command for Unix prompt. You can check the specifications at official documentations below:
- https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/copy
- https://www.man7.org/linux/man-pages/man1/cat.1.html
Comparison #1
Suppose we have two text files, a.txt
and b.txt
. Each of them has simple contents.
We gotta combine them into one text file, c.txt
.
In Windows, it would be like this:
1 | C:\Users\qmffk\Downloads>copy a.txt + b.txt c.txt |
In Linux, it would be like this:
1 | thanang@ROSS-DESKTOP:/mnt/d/test$ cat a.txt b.txt > c.txt |
Both look like the same, but there is a difference between two c.txt
.
Using WinMerge, we can see the additional character 1A
(in hex) at Windows’ c.txt
. In short, the character 1A
(26
in decimal) is appended for indicating an EOF (= End Of File). This is why this is mentioned in the documentation. (For more information about the character 1A / 032 / SUB / Substitute
, visit here)
1 | ...You can copy an ASCII text file that uses an end-of-file character (CTRL+Z) to indicate the end of the file... |
So, how do we prevent from appending the EOF character ? This is also mentioned in the documentation.
1 | The effect of /b depends on its position in the command–line string: - If /b follows source, the copy command copies the entire file, including any end-of-file character (CTRL+Z). - If /b follows destination, the copy command doesn't add an end-of-file character (CTRL+Z). |
Comparison #2
Do combine a.txt
and b.txt
into c.txt
again.
In Windows, it would be like this:
1 | C:\Users\qmffk\Downloads>copy /b a.txt + b.txt c.txt |
In Linux, it would be the same with before.
Using WinMerge, we can see they are the same.
So, you should plus the flag /b
in copy
commandline for experiencing the same result as cat
in Unix.