Equivalent of 'more' or 'less' command in Powershell?

Viewed 101311
14 Answers

Yes there is:

some-cmdlet | out-host -paging

Well... There is "more", which is more or less (...) the same you'd expect from other platforms. Try the following example:

dir -rec | more

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.

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.

Another option is to use less through the WSL:

some-cmdlet | wsl less

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 :-)

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.

Related