Display the contents of one or more text files.
Syntax TYPE [drive:]pathname(s)
If more than one file is specified the filenames are included in the output.
If a wildcard is used the filenames are displayed even if only one file matches. The file names are printed to the error stream and so can be hidden by redirecting to NUL TYPE * 2>nul
If the file(s) were successfully displayed %ERRORLEVEL% = 0
If the file was not found or bad parameters given %ERRORLEVEL% = 1
TYPE is an internal command.
Redirect output into a new file:
TYPE file.txt > Newfile.txt
Append output to an existing file:
TYPE file.txt >> ExistingFile.txt
To do the same with user console input :
TYPE CON > Newfile.txt
This will require typing a CTRL-Z to indicate the end of file.
When using redirection to SORT a file the TYPE command is used implicitly
SORT < MyFile.txt
Create an empty (zero byte) file:
TYPE nul >filename.log
Check filesize during a download (to monitor progress of a large download) Since TYPE won't lock the file, this does not pose a threat to the download completing successfully:
TYPE file_being_downloaded >NUL DIR file_being_downloaded
Convert an ASCII (Windows1252) file into a Unicode (UCS-2 le) text file:
For /f "tokens=2 delims=:" %%G in ('CHCP') do Set _codepage=%%G
CHCP 1252 >NUL
CMD.EXE /D /A /C (SET/P=ÿþ)<NUL > unicode.txt 2>NUL
CMD.EXE /D /U /C TYPE ascii_file.txt >> unicode.txt
The technique above (based on a script by Carlos M.) first creates a file with a Byte Order Mark (BOM) and then appends the content of the original file. CHCP is used to ensure the session is running with the Windows1252 code page so that the characters 0xFF and 0xFE (ÿþ) are interpreted correctly.
It is also possible to convert files from Unicode to ASCII with TYPE or MORE see the redirection syntax page for details.
“Writing is easy; all you do is sit staring at a blank sheet of paper until the drops of blood form on your forehead” ~ Gene Fowler
MORE - Display output, one screen at a time.
SORT - Sort input.
STRINGS - Search for ANSI and UNICODE strings in binary files (SysInternals).
Powershell: Get-Content - Get content from item (cat / type / gc).
Equivalent bash command (Linux): cat - Display the contents of a file.