Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix tail equivalent command in Windows Powershell

I have to look at the last few lines of a large file (typical size is 500MB-2GB). I am looking for a equivalent of Unix command tail for Windows Powershell. A few alternatives available on are,

http://tailforwin32.sourceforge.net/

and

Get-Content [filename] | Select-Object -Last 10

For me, it is not allowed to use the first alternative, and the second alternative is slow. Does anyone know of an efficient implementation of tail for PowerShell.

like image 496
mutelogan Avatar asked Dec 13 '10 06:12

mutelogan


People also ask

How do you tail a file in Windows PowerShell?

Open it with notepad $PROFILE. Then in the text document, create a new function: function Tail ($path) { Get-content -tail 15 -path $path -wait } This way you can access the function each time you start PowerShell. This should be the accepted answer.

Is there a tail command for Windows?

An advanced tail -f command with GUI, MakeLogic Tail is the tail for Windows. It can be used to monitor the log files of various servers and comes with a variety of other intuitive and useful features.

Does PowerShell have Linux commands?

Running Basic PowerShell Commands on Linux Being a cross-platform scripting language, PowerShell on Linux supports all of the commonly known commands from CMD and Linux's command line shell such as sudo apt update . No need to open a Bash terminal! From here on out you can run thousands of built-in PowerShell commands.

What is the equivalent of grep in PowerShell?

The simplest PowerShell equivalent to grep is Select-String. The Select-String cmdlet provides the following features: Search by regular expressions (default); Search by literal match (the parameter -Simple);


1 Answers

Use the -wait parameter with Get-Content, which displays lines as they are added to the file. This feature was present in PowerShell v1, but for some reason not documented well in v2.

Here is an example

Get-Content -Path "C:\scripts\test.txt" -Wait 

Once you run this, update and save the file and you will see the changes on the console.

like image 121
ravikanth Avatar answered Oct 13 '22 15:10

ravikanth