How to echo contents of file in a DOS/Windows command prompt

86

16

Possible Duplicate:
How can I print a textfile on the command prompt in Windows?

Like in Unix' cat filename ...
Can this be done?

t123

Posted 2011-03-12T12:56:23.180

Reputation: 1 525

Question was closed 2011-03-12T22:24:48.407

Answers

110

You can do this with type filename :)

Azz

Posted 2011-03-12T12:56:23.180

Reputation: 3 777

7

You can cat multiple files like this:

type file1 file2 file3 2>nul

The 2>nul suppresses the output of the filenames. If a file doesn't end with a carriage return, one will not be added between files.

You can do the same thing like this:

copy file1 + file2 + file3 con >nul

In this case the >nul suppresses output of the file names and the n file(s) copied message.

Paused until further notice.

Posted 2011-03-12T12:56:23.180

Reputation: 86 075

6

In your command prompt, use the "type" command. You can also pipe it through "more" like in Unix.

  • type filename

...or...

  • type filename | more

Randolf Richardson

Posted 2011-03-12T12:56:23.180

Reputation: 14 002

Additionally, you can use other redirection operators that are the same as Unix in that you can store output into a file instead of onto the screen (e.g., type filename > filename.out) or take input from a file (e.g., more < filename). It is important to note that the more advanced uses of these redirection operators that will work in Unix don't always work as expected (if at all) in DOS/Windows environments, but if you keep things simple (and test them) they should always work well for you. – Randolf Richardson – 2011-03-12T13:10:18.690