type - Display a Text File
Being able to quickly check the contents of a text file is very useful when working with the command prompt or batch files.
This article introduces how to display the contents of a text file using the type command.
Basics of the type command
The type command displays the contents of a text file on the screen.
You can check the contents directly at the command prompt without opening the file.
Basic usage at the command prompt
When you run this command, the contents of the sample.txt file are displayed on the screen.
Basic usage in a batch file
@echo off
setlocal
type sample.txt
endlocal
exit
When you run this batch file, the contents of the sample.txt file are displayed on the screen.
type command syntax
The basic syntax of the type command is as follows.
type [drive:][path]filename
Parameter description
| Parameter | Description |
|---|---|
[drive:][path]filename | Specifies the location and name of the file to display |
/? | Displays help at the command prompt |
If the file name contains spaces, it must be enclosed in double quotation marks (").
type command examples
Displaying a single file
As the most basic usage, display a single text file.

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Displaying multiple files in sequence
By specifying multiple file names separated by spaces, you can display multiple files in sequence.
When you specify multiple files, the file name is displayed before each file.
You can also display multiple files together by using a wildcard, such as type *.txt.
When the file name contains spaces
If the file name contains spaces, enclose it in double quotation marks.
Combining with pipes
For long files, you can combine it with the more command to display one page at a time.
When you run this command, the contents of the file are displayed one page at a time, and you can move to the next page by pressing the Space key or the Enter key.
Searching the contents of a file
By combining it with the find command, you can display only the lines in a file that contain a specific string.
Practical examples in batch files
Check the contents of a log file
@echo off
setlocal
echo ========================================
echo Displaying the contents of the log file
echo ========================================
echo.
type error.log
endlocal
exit
Display multiple configuration files at once
@echo off
setlocal
echo ========================================
echo Contents of the configuration files
echo ========================================
echo.
echo [Database settings]
type db_config.txt
echo.
echo [Server settings]
type server_config.txt
echo.
echo [Application settings]
type app_config.txt
endlocal
exit
Concatenate multiple files into one file
By redirecting the output of type, you can combine multiple text files into one.
@echo off
setlocal
type part1.txt part2.txt > merged.txt
echo Files have been concatenated
endlocal
exit
However, because the file name lines are also output, use copy /b part1.txt+part2.txt merged.txt if you want to concatenate only the contents. For copying files, the basic approach is to use the copy command rather than type.
For redirection, see the following page.
Notes
When you display a binary file or a file created by a program with the type command, strange characters may appear on the screen.
This is caused by the control codes contained in binary files.
In general, we recommend using the type command only to display text files.
When you display a UTF-8 file, Japanese text may appear garbled.
In that case, switch the code page to UTF-8 with chcp 65001 and then run the command.
For details on character encoding, see the following page.
Using it in PowerShell
In PowerShell, type works as an alias for the Get-Content cmdlet.
The syntax differs, but you can display the contents of a file in the same way.
type sample.txt
# or
Get-Content sample.txt
Summary
The type command is a handy tool for quickly checking the contents of a text file.
Main features:
- Simple and easy-to-use syntax
- Multiple files can be displayed at the same time
- Can be combined with other commands using pipes
- Well suited to automation in batch files
Because you can check the contents without opening the file, it greatly improves work efficiency.
It is especially useful for everyday tasks such as checking log files and configuration files.