---
title: "How to Quickly Display Files With PowerShell Cat"
description: "Learn all the ways to emulate a PowerShell cat command just as Linux has. In this tutorial take control of your text files!"
canonical: "https://adamtheautomator.com/powershell-cat/"
---

# How to Quickly Display Files With PowerShell Cat

> Learn all the ways to emulate a PowerShell cat command just as Linux has. In this tutorial take control of your text files!

Source: https://adamtheautomator.com/powershell-cat/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Quickly Display Files With PowerShell Cat](https://adamtheautomator.com/wp-content/uploads/2022/06/Quickly-Display-Files-With-PowerShell-Cat.jpg)

# How to Quickly Display Files With PowerShell Cat

[![](https://secure.gravatar.com/avatar/b4cd4a109fc359fca6ccc8a192dd75bf9a440677bb2a87da8c23f48d76b3bb39?s=192&d=mm&r=g)Edem Afenyo](https://adamtheautomator.com/author/edem-afenyo/)12 July 20226 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Setting Up the Tutorial Directory](#setting-up-the-tutorial-directory)
*   [Unveiling the PowerShell Cat Command](#unveiling-the-powershell-cat-command)
*   [Displaying the Contents of a File with PowerShell Cat](#displaying-the-contents-of-a-file-with-powershell-cat)
*   [Showing Lines from the Top](#showing-lines-from-the-top)
*   [Showing Line from the Bottom](#showing-line-from-the-bottom)
*   [Merging Contents Into a New File](#merging-contents-into-a-new-file)
*   [Appending the Contents of One File to Another](#appending-the-contents-of-one-file-to-another)
*   [Filtering Files](#filtering-files)
*   [Displaying All Files](#displaying-all-files)
*   [Displaying Files with Specific File Extensions](#displaying-files-with-specific-file-extensions)
*   [Filtering with Exclusion](#filtering-with-exclusion)
*   [Paginating the Output](#paginating-the-output)
*   [Conclusion](#conclusion)

Are you thinking of displaying the contents of files either for automation or troubleshooting purposes? How about editing and managing files based on the contents of another file? Don’t worry; PowerShell cat is an excellent tool in your arsenal.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

In this tutorial, you will learn to harness the versatility of the PowerShell cat to display your files’ contents in many ways.

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, all you need is a computer with Windows PowerShell 5.1 or PowerShell 7 and up. This article uses a [Windows 10](https://en.wikipedia.org/wiki/Windows_10) machine with PowerShell 5.1

Related:[How to Walk Through a PowerShell 7 Upgrade](https://adamtheautomator.com/powershell-7-upgrade/)

## Setting Up the Tutorial Directory

To have a more consistent experience while following this tutorial, prepare a tutorial directory by performing the following steps.

1\. Open a PowerShell window and create a new folder _c:\\PsCat_ by executing the below command. This new folder will be your working directory throughout this tutorial.

```powershell
# Create the C:\PsCat folder and change the working directory
New-Item -Type Directory -Path C:\PsCat -Force ; Set-Location C:\PsCat
```

![Creating the tutorial directory](https://adamtheautomator.com/wp-content/uploads/2022/06/image-684.png)

Creating the tutorial directory

2\. Next, run the below commands to create three sample files with different contents.

```powershell
# Create File1.txt containing 5 lines
1..5 | ForEach-Object { "File1.txt: Line $_" } | Out-File File1.txt
# Create File2.txt containing 10 lines
1..10 | ForEach-Object { "File2.txt: Line $_" } | Out-File File2.txt
# Create File3.txt containing 100 lines
1..100 | ForEach-Object { "File3.log: Line $_" } | Out-File File3.log
```

3\. Finally, list the tutorial directory contents.

```powershell
# List the current directory contents
Get-ChildItem
```

You should see three files; File1.txt, File2.txt, and File3.log.

![Creating the sample tutorial files](https://adamtheautomator.com/wp-content/uploads/2022/06/image-685.png)

Creating the sample tutorial files

## Unveiling the PowerShell Cat Command

Those who worked on Linux may be familiar with cat as the command to read the contents of a file. The PowerShell cat command has the same function. But note that the PowerShell cat is only an [alias](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_aliases?view=powershell-7.2) of the [Get-Content](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2) cmdlet.

Apart from cat, there are other aliases for the Get-Content command, which you can find out by running the below command.

```powershell
Get-Alias -Definition Get-Content
```

As you can see below, `gc` and `type` are also aliases of `Get-Command`, along with `cat`.

![Getting the PowerShell cat aliases](https://adamtheautomator.com/wp-content/uploads/2022/06/image-686.png)

Getting the PowerShell cat aliases

Related:[PowerShell Get-Content a PowerShell Tail Equivalent](https://adamtheautomator.com/powershell-get-content/)

> _This tutorial will only use cat as the Get-Content alias for consistency._

## Displaying the Contents of a File with PowerShell Cat

The primary and most basic usage of the PowerShell `cat` is showing a file’s contents on the screen. Running the `cat` command followed by the filename will tell the command to output the file’s contents for display only.

Run the below command to read the `File1.txt` file and output the data on the screen.

```powershell
cat File1.txt
```

You should see the contents of File1.txt on your screen, as shown below.

![](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/d88d9caf-b82d-45b3-a572-1e5f7bc710d7/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220621%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220621T021832Z&X-Amz-Expires=86400&X-Amz-Signature=9403e947d5a123ee86259b9ebe162a434154194283a0f70bc5ffae96f95f1e35&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22Untitled.png%22&x-id=GetObject)

Displaying the Contents of a File with PowerShell Cat

### Showing Lines from the Top

Reading or displaying a file’s entire content is not always practical, especially when dealing with huge files with hundreds of lines or so.

Reading the first few lines of the file may help identify whether the file is what you need. PowerShell `cat` allows you to display a specific line or lines from a file to have a quick look.

To display a collection of lines from the beginning of the file, specify the `-TotalCount` parameter followed by the number of lines. The `-TotalCount` parameter also has aliases `-Head` and `-First`, which you may use interchangeably.

Run the below command to display the first five lines in _`c-text.txt`._

> _The -TotalCount parameter has aliases too, which are -Head and -First that you may use interchangeably._

```powershell
cat File2.txt -TotalCount 5
```

The result will display only the first five lines, as shown below.

![Displaying the first five lines with PowerShell cat](https://adamtheautomator.com/wp-content/uploads/2022/06/image-687.png)

Displaying the first five lines with PowerShell cat

### Showing Line from the Bottom

On the other hand, you can also view the file’s contents from the bottom by specifying the `-Tail` parameter or its alias, which is `-Last`. This method is typical when troubleshooting with log files, where it is common only to know the last set of entries before a program crashes.

Execute `cat` with the `-Tail` parameter to view the last five lines of `File2.txt`.

```powershell
cat File2.txt -Tail 5
```

The output in your terminal should resemble the result below, showing you the last five lines from the bottom.

![Displaying the last five lines with PowerShell cat](https://adamtheautomator.com/wp-content/uploads/2022/06/image-688.png)

Displaying the last five lines with PowerShell cat

## Merging Contents Into a New File

Instead of simply showing the content on the screen, you can redirect the [standard out](http://steve-jansen.github.io/guides/windows-batch-scripting/part-4-stdin-stdout-stderr.html#:~:text=The%20%E2%80%9CStandard%20Out%E2%80%9D%20file%2C,for%20display%20on%20the%20screen.) of a command to a new file in PowerShell. Moreover, the PowerShell cat can read multiple files at once, which makes merging contents possible.

1\. Run the cat command to concatenate File1.txt and File2.txt as follows. The output redirect (>) sends the command output to the new file called c-text.txt.

```powershell
cat File1.txt,File2.txt > Merge1.txt
```

You can also achieve the same result by piping the cat output to Out-File instead of using the redirect operator (>).

```powershell
cat File1.txt,File2.txt | Out-File Merge1.txt
```

Related:[Redirecting Output to a File with the PowerShell Out-File Cmdlet](https://adamtheautomator.com/out-file/)

2\. Execute cat again to display the contents of the new Merge1.txt file as follows.

```powershell
cat Merge1.txt
```

The screenshot below should be similar to the output on your screen. As you can see, you have successfully merged the contents of the File1.txt and File2.txt files into the new Merge1.txt file.

![Concatenating Multiple Files](https://adamtheautomator.com/wp-content/uploads/2022/06/image-689.png)

Concatenating Multiple Files

3\. Finally, delete Merge1.txt to maintain the original set of files in the tutorial directory.

```powershell
Remove-Item Merge1.txt
```

## Appending the Contents of One File to Another

Another thing you can do with the Linux [cat](https://www.tecmint.com/13-basic-cat-command-examples-in-linux/) command is appending the contents of one file to another instead of overwriting the file or creating a new one.

Below are two ways in PowerShell to append the content to a file. The first method pipes the PowerShell cat output (|) to the Add-Content cmdlet. The second method uses the double output redirection symbol (>>).

1\. Run any of the below commands, and the result will be the same.

```powershell
# PowerShell cat with Add-Content
cat File1.txt | Add-Content File2.txt

# PowerShell cat with double redirection symbol (append)
cat File1.txt >> File2.txt
```

2\. Run the following command to confirm the added content of the File2.txt file.

```powershell
cat File2.txt
```

At the tail end of the file, you should see the contents of File1.txt, similar to the image below.

![Appending One File to Another](https://adamtheautomator.com/wp-content/uploads/2022/06/image-690.png)

Appending One File to Another

3\. Now that you’ve demonstrated appending contents to an existing file, run the below command to overwrite the tutorial file File2.txt with its original contents.

```powershell
# Overwrite File2.txt containing 10 lines
1..10 | ForEach-Object { "File2.txt: Line $_" } | Out-File File2.txt
```

## Filtering Files

The PowerShell cat accepts wildcards and patterns as location inputs. This feature comes in handy when there are mixed types or filenames, and you want to filter, include, or exclude items.

### Displaying All Files

Your current working directory contains three files, two \*.txt and one \*.log. To display the contents of every file in this directory, specify the asterisk (\*) wildcard at the end of the path.

```powershell
cat .\\*
```

Your terminal should quickly display the contents of all files. The below animation has reduced speed for better demonstration.

![Displaying the contents of all files](https://adamtheautomator.com/wp-content/uploads/2022/06/image-7.gif)

Displaying the contents of all files

### Displaying Files with Specific File Extensions

What if you only need to read files with specific file extensions? There are several ways you can do so. For example, you only need to read \*.txt files. The first way is to apply the wildcard to the input path. Run the below command to read all files with the \*.txt extension.

```powershell
cat *.txt
```

![Using a wildcard pattern to display files with specific extensions](https://adamtheautomator.com/wp-content/uploads/2022/06/image-691.png)

Using a wildcard pattern to display files with specific extensions

Another way is to specify the `-Include` parameter followed by the wildcard pattern. Run the command below to read all files in the folder but only _include_ files with the `*.txt` extension.

```powershell
cat .\\* -Include *.txt
```

![Using a wildcard pattern to include files with specific extensions](https://adamtheautomator.com/wp-content/uploads/2022/06/image-692.png)

Using a wildcard pattern to include files with specific extensions

### Filtering with Exclusion

Instead of specifying which files to include, add the -Exclude parameter. For example, run the code below to filter all files with the \*.txt extension excluding File2.txt.

```powershell
cat .\\* -Filter *.txt -Exclude File2.txt
```

As you can see below, even though `File2.txt` match the `*.txt` filter, PowerShell `cat` ignored it because the filename is in the `-Exclude` list.

![Filtering files with an exclusion](https://adamtheautomator.com/wp-content/uploads/2022/06/image-693.png)

Filtering files with an exclusion

## Paginating the Output

When you run cat to display large files results in a fast-moving stream of text that only stops after reaching the bottom. This behavior is not too helpful for reading the contents of a file.

To make reading large files on the screen manageable, you can apply pagination to your output. Pagination allows you to view only the contents that fit on the window.

You can achieve pagination by piping the PowerShell `cat` output to the built-in `more` function or the `Out-Host` cmdlet.

For example, run either below commands to display the `File3.log` with pagination. Either command will produce the same result and interaction options.

```powershell
cat File3.log | more
# OR
cat File3.log | Out-Host -Paging
```

The result only shows you the contents that fit your current window size.

![PowerShell cat pagination with more](https://adamtheautomator.com/wp-content/uploads/2022/06/image-694.png)

PowerShell cat pagination with more

![PowerShell cat pagination with Out-Host -Paging](https://adamtheautomator.com/wp-content/uploads/2022/06/image-695.png)

PowerShell cat pagination with Out-Host -Paging

At this point, you have three options for interaction.

*   Press `SPACE` to display the next whole page.
*   Press carriage return (`CR`) or `Enter` to display the following line.
*   Press `q` to exit the pagination.

## Conclusion

Congratulations! By making it this far, you have learned to use `cat` to display files in PowerShell. PowerShell cat is an alias for `Get-Content` and is a versatile tool.

You can achieve more with PowerShell cat than what this tutorial covered. For your next step, further expand your knowledge on [Get-Content, this time as a Tail equivalent](https://adamtheautomator.com/powershell-get-content/).

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-cat%2F&text=How%20to%20Quickly%20Display%20Files%20With%20PowerShell%20Cat)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-cat%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-cat%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b81e69730da4c690758c2/4afeea42b7f854d23285b281664351779f042510f1e3a1d766d02cfa39b711a8.jpg)

### [Find and Disable Every Inactive AD Computer with PowerShell](/find-inactive-computers-active-directory/)

Find inactive computer accounts in Active Directory with Search-ADAccount, then disable and quarantine them with PowerShell in steps you can undo.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b814eba23fbf8d18b64a2/ade916ad78256face2456a10aacfbb82051f4957bf03d6f163193b25395e5183.jpg)

### [Back Up and Restore Every Group Policy Object in PowerShell](/backup-restore-gpos-powershell/)

Back up every Group Policy Object with Backup-GPO, restore one or all with Restore-GPO, and recover a deleted GPO with Import-GPO and New-GPLink.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b8181be1be294c37c6724/0ba6a36aaba4a30390fca48d395a19d38846d030302d345372b68b077c3a5cdc.jpg)

### [Find Stuck DFS Replication Backlogs with PowerShell](/dfs-replication-backlog-powershell/)

Find out whether DFS Replication is caught up. Get-DfsrBacklog reads the full file count past the 100-file limit, then a loop checks every group.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
