Unix tail equivalent command in Windows Powershell

Unix has a tail command which helps us in reading the file content in the shell window. If the file size is very large then we could run a simple tail command and read the last 100 lines of the file. We do use this in reading the huge logs which will take more  time to open or download. So What is the Unix tail equivalent command in Windows Powershell?

PowerShell version 1.o and 2.0 doesn’t have the built-in tail command. However, there is an alternate approach to reading the file contents. Let’s take a look at in detail.

Unix tail equivalent command in PowerShell Version 1.0 and 2.0

Running the below command will show the lines that get added to the file. To see the live example run this command and try to update the text file and come back to the console, you could see the updated text displayed over here.

Unix tail equivalent command in PowerShell Version 3.0 and above

PowerShell 3.0 and above comes up with a flag -Tail on Get-Content. The example below demonstrates the -Tail flag.

gets the last 10 lines of the file

gets the last 10 lines of the file and waits for more

Note: Get-Content also has aliases defined. For example, if you are used to UNIX you might like cat, and there are also type and gc.

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.