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

后端 未结 12 1839
小蘑菇
小蘑菇 2020-12-13 01:38

Is there a way to paginate the output by piping it to some \'more\' command, which is available in linux\\unix shells?

相关标签:
12条回答
  • 2020-12-13 01:43

    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 ; .\temp.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

    0 讨论(0)
  • 2020-12-13 01:49

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

    0 讨论(0)
  • 2020-12-13 01:51

    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.

    0 讨论(0)
  • 2020-12-13 01:52

    Yes there is:

    some-cmdlet | out-host -paging

    0 讨论(0)
  • 2020-12-13 01:57
    cat C:\Temp\test.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\test.txt -wait 
    

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

    cat C:\Temp\test.txt | oh –Paging
    

    oh = Out-Host

    0 讨论(0)
  • 2020-12-13 01:58

    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.

    0 讨论(0)
提交回复
热议问题