Home » PowerShell » Windows- Cat Equivalent Command in PowerShell and cmd

Windows- Cat Equivalent Command in PowerShell and cmd

What is the cat command and how to use cat in Windows or windows cat equivalent?

cat command ( short for concatenate) is one of the powerful commands to create single or multiple files, view the contents of the file, concatenate multiple files, copy the content to other files, and print output to the terminal or file.

The cat command is mostly used in Linux and other operating systems. The cat command is called cat as it is used to concatenate files. For example, to display the contents of a file, use cat filename.txt, to view the large file, use cat filename.txt | more

If you use the cat command in windows cmd (command prompt/command line), it will throw an exception as 'cat' is not recognized as an internal or external command, operable program, or batch file.

cat command in windows cmd (command prompt)
cat command in windows cmd (command prompt)

In the Microsoft Windows operating system, if you use the help cat command in Windows PowerShell terminal, it gives the below output

PS C:\> help cat
NAME
    Get-Content

SYNTAX
    Get-Content [-Path] <string[]> [-ReadCount <long>] [-TotalCount <long>]
    [-Tail <int>] [-Filter <string>] [-Include
    <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] 
    [-UseTransaction] [-Delimiter <string>]
    [-Wait] [-Raw] [-Encoding {Unknown | String | Unicode | Byte | 
    BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii |
    Default | Oem | BigEndianUTF32}] [-Stream <string>]  [<CommonParameters>]

    Get-Content -LiteralPath <string[]> [-ReadCount <long>] [-TotalCount <long>]
    [-Tail <int>] [-Filter <string>]
    [-Include <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>]
     [-UseTransaction] [-Delimiter
    <string>] [-Wait] [-Raw] [-Encoding {Unknown | String | Unicode | Byte | 
    BigEndianUnicode | UTF8 | UTF7 | UTF32 |
    Ascii | Default | Oem | BigEndianUTF32}] [-Stream <string>]  [<CommonParameters>]


ALIASES
    gc
    cat
    type


REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. 
    It is displaying only partial help.
        -- To download and install Help files for the module that includes 
     this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: 
     "Get-Help Get-Content -Online" or
           go to https://go.microsoft.com/fwlink/?LinkID=113310.

Help cat command in windows PowerShell output.

Cool Tip: cat in Windows alias are type, gc, and Get-Content

In the above PowerShell terminal, the help cat command gives output as Get-Content and other aliases used for cat alternative in windows. You can use the windows cat equivalent cmdlets like type, gc and Get-Content.

The type command is a Windows cat equivalent that works across a command-line prompt (cmd) and a Windows PowerShell. type command used in Windows to view the contents of the given file without modifying it.

In this post, we will discuss how to display the contents of a file on the screen using the cat equivalent in windows.

Windows Cat equivalent in cmd & PowerShell : type

type command syntax in windows

Syntax

type [<Drive>:][<Path>]<FileName>

Parameters

[<Drive>:][<Path>] : location and name of the file to use for viewing contents.

<FileName> : Single file name or separate multiple file names with spaces on cmd

Windows Cat equivalent – type command Examples

To get help on type command

type /?

The above command in cmd gets help on windows cat equivalent type command and displays contents of a text file or files. Help command gives output as

TYPE [drive:][path]filename

To view single file content using type command

C:\>type file.txt

It will display a view of the file.txt file as given in the below image

powershell cat type view file content
window type command – view file content

Cool Tip: How to get permissions on folders and subfolders!

Windows Cat equivalent – view multiple file content using type

Sometimes, it is necessary to view the content of the file which is locked by another program and also copy the content to another file. type command in windows provides an easy way of doing it.

C:\> type file1.txt ,file2.txt > resultfile.txt
C:\> type resultfile.txt

In the above command, we have used two files separated by, (comma) in PowerShell. If you are using a command prompt use separator as space. Two files of concatenated output will be stored in resultfile.txt.

The second command, type resultfile.txt display contents on the screen. windows cat equivalent type command doesn’t lock the file it is viewing on the screen.

Cool Tip: Use set-aduser to modify active directory user attributes!

To view large-sized file content

C:\>type logs.txt | more

Sometimes, we may need to view the contents of a lengthy file like a log file. In order to view lengthy content, use more a filter to view content on the screen one line at a time.

type Command FAQ

What is the cat equivalent command in windows?

The type command is a Windows cat equivalent that works on command-line prompt and a Windows PowerShell.

You can also use GC-Content cmdlet as an alias for the cat command in windows.

How to use cat command in windows?

Use type command in windows to view the contents of the text file or files. If you need more help, use type /?
type command syntax is TYPE [drive:][path]filename

what is the windows equivalent of the Unix command cat?

cat command in Unix is used to concatenate files and print content. windows type command is used to display the content of the text file. You can also use Get-Content cmdlet to display content

‘cat’ is not recognized as an internal or external command

cat command not used in windows. If you use cat in windows command prompt (cmd), it will display a message as `cat` is not recognized as an internal or external command, operable command, or batch script.

use type command in the command line or PowerShell. However, if you use Get-Help cat on PowerShell, it gives output as Get-Content which is an alias of type command.

Best type command windows example

type command best feature is to view the content of the file without locking the file and even copy the contents of the file which are locked by another program to a different file

How to concatenate two text files in PowerShell?


Let’s consider two files file1.txt and file2.txt, to concatenate two files using PowerShell, use the below command

type file1.txt file2.txt > resultfile.txt

above command concatenate file1.txt and file2.txt into resultfile.txt file.

Does cat command work in Windows?

The cat command is used to create single or multiple files, concatenate files, and view the contents of the file.
cat command in windows doesn’t work. If you type cat in windows cmd, it will throw an error as `cat` is not recognized as an internal or external command.

However, you can use the cat alias command Get-Content or type to perform the same operation as the cat command.

Why is the cat command used?


The cat command in Unix/Linux systems is used to read the content of the file and print the output of the file on to the console.

Cool Tip: Know more about how to get aduser using userprincipalname!

Conclusion:

Windows operating system doesn’t have the cat command in Windows. using the cat command in cmd line, it will throw an exception as “‘cat’ is not recognized as an internal or external command, operable program or batch file”.

However, using the cat command in PowerShell displays its alias command as Get-Content and type.

type command is a built-in alias of the Get-Content cmdlet which also displays the contents but with a different syntax.

In the above post, I explained how to use cat equivalent command in Windows using a built-in command type to display file contents, view lengthy files, and view multiple files contents.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.