[Solved] Equivalent of ‘more’ or ‘less’ command in Powershell?

Is there a way to paginate the output by piping it to some ‘more’ command, which is available in linuxunix shells?

Solution #1:

Yes there is:

some-cmdlet | out-host -paging

Respondent: Shay Levy

Solution #2:

Well… There is “more”, which is more or less (…) the same you’d expect from other platforms. Try the following example:

dir -rec | more
Respondent: Jouni Heikniemi

Solution #3:

dir -rec | more is bad advice.

It will cause powershell to evaluate the entire command prior to outputting it to the screen, something that is not needed for something like output paginating

In some extreme cases, it could cause the system to crash (e.g. dir 'C:' | more)

On the other hand, using out-host -paging will output information to the screen as it is available.

Respondent: Xavier Chorin

Solution #4:

The Powershell Community Extensions have a handy function named ‘less’ that provides a more complete Unix-style feature set, using a ported copy of less.exe to actually handle the paging.

You can install it by starting an admin shell and running:

Find-Package pscx | Install-Package -Force

(the force is to upgrade older versions)

You can pipe strings to it, or give filenames as direct parameters.

type foo.txt | less
less foo.txt, bar.txt, baz.txt

It works in ConEmu and Powershell windows, but unfortunately it doesn’t work the way you’d expect under the v2.0 ISE.

Respondent: Richard Berg

Solution #5:

I prefer the “less” command over the “more” command. With the less command, results can also be paged backwards instead of just forwards.

The “less” from Git for Windows works for me*

To save typing I added the alias “l” for less in my Powershell profile (notepad $profile):

sal l "C:Program Files (x86)Gitinless.exe"

Look for less either in the above path or C:Program FilesGitusrinless.exe or similar.


*: I had errors in Powershell with the Gow version of “less”.

Respondent: Josh

Solution #6:

PS> cd C:

PS> dir -r -ex 0 | out-Host -paging

PS> dir -file -r -ea 0 c:Windows | Select FullName,Length,LastWriteTime | out-gridview
Respondent: Bimo

Solution #7:

more isn’t used to limit output, it’s used to paginate output and make it easier to read in a terminal, if anything.

Are you talking about using head and tail? EggHeadCafe has an example of:

type my.txt | select-object -first 10

type my.txt | select-object -last 10

to emulate head and tail.

Respondent: Mark Rushakoff

Solution #8:

I added a function definition and alias to my default profile at
%SystemRoot%system32windowspowershellv1.0profile.ps1

This function is mostly based on this blog entry by Aman Dhally with added exception handling for pressing Q while paging.

function more2
{
   param(
     [Parameter(ValueFromPipeline=$true)]
     [System.Management.Automation.PSObject]$InputObject
   )

   begin
   {
      $type = [System.Management.Automation.CommandTypes]::Cmdlet
      $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(‘Out-Host’, $type)
      $scriptCmd = {& $wrappedCmd @PSBoundParameters -Paging }
      $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
      $steppablePipeline.Begin($PSCmdlet)
   }

   process
   {
      try
      {
         $steppablePipeline.Process($_)
      }
      catch
      {
        break;
      }
   }

   end
   {
      $steppablePipeline.End()
   }

   #.ForwardHelpTargetName Out-Host
   #.ForwardHelpCategory Cmdlet
}

New-Alias more more2

so I can just call it like dir -r | more and it immediately starts paged output because of PowerShell’s pipeline (as opposed to waiting for the complete output with more.com).

Respondent: oleschri

Solution #9:

If you have VIM installed, I thoroughly enjoy dir -r | vim -R -. Unfortunately this suffers the same problem with more (ie. no streaming).

Respondent: mvanle

Solution #10:

cat C:Temp	est.txt

cat is an alias for Get-Content – with larger files you will get the — More — output at the bottom of the terminal

You can also you can add -wait

cat C:Temp	est.txt -wait 

-wait is like using tail but it actually is rerunning the command just refreshing the output

cat C:Temp	est.txt | oh –Paging

oh = Out-Host

Respondent: Terminal Bash

Solution #11:

I had exactly this question (well I wanted less, not more) and found the answer of @richard-berg worked for me, being new to PowerShell (but not to Linux), I found the things missing from that answer (for me) were:
I first needed to go:

Find-Package pscx | Install-Package

which then prompted for “installing nuget package”. I did this but then had to use the
-AllowClobber parameter on Install-Package.

then in order to use less, I had to:

Set-ExecutionPolicy RemoteSigned

which all worked 🙂

Respondent: Bill Naylor

Solution #12:

Suggestion: Put the file into a temporary/disposable .txt file, then let the OS invoke your favorite editor, the one that is linked to the .txt extension.

Get-Process | Out-File temp.txt ; . emp.txt

Note: each time you use this you will overwrite any pre-existent temp.txt file.
Pick the file name wisely.

The above is just a basic idea.
Next step would be transforming this into “| more” using aliases or profile functions, etc.

HTH,
Marcelo Finkielsztein

Respondent: Marcelo Finki

Solution #13:

The easiest thing to do in my opinion is to use Scoop to install anything you’re used to using from UNIX. Once you do, just run scoop install less and you’re good to go.

Respondent: kjohnsen

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.