26

What is the powershell equivalent of 'less'?

I see 'more', but it lacks some of the features I rely on (e.g. searching through the file)

I seek a pager (equivalent of 'less') which allows searching (match or ignore case), multiple files at once, etc.

Some of our servers run windows 2008 and I lack admin privileges to install cygwin

I had heard windows 2008, MSFT got their act together and provided some easy-for-admins tools.

Update:

I should give some context:

  • I know little about power shell
  • New servers have 2008 on them
  • While I affection for many tools of yore, the dos prompt is not one of them
  • I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
  • I understood that powershell gave us those tools
  • I fired off my question quickly.

thanks

xhienne
  • 5,738
  • 1
  • 15
  • 34
user331465
  • 2,984
  • 13
  • 47
  • 77

6 Answers6

22

It reads like you know you can do this:

gc logfile.log | more

(GC is an alias for Get-Content).

You may be able to do the filtering etc.. with this more information can be found by running these commands:

Get-Help Get-Content Get-Help

Get-Content -Examples

(Get-Help gc would work fine as well).

And the bits you may be interested in are limit\filter etc...

Get-Help gc -Parameter * | more

Community
  • 1
  • 1
Matt
  • 1,931
  • 12
  • 20
  • Do not works with objects, things are not separated by objects – MUY Belgium Sep 09 '14 at 15:00
  • @MUYBelgium I don't follow your comment, the command is used to read large amount of text. what are you trying to do with an object? – Matt Sep 14 '14 at 16:56
  • 1
    This does not work for very large (big data) files. gc pulls it alll into memory. – Gabriel Fair Apr 13 '15 at 04:53
  • 4
    @garglblarg Actually [`more` was originally an old command from unix](https://en.wikipedia.org/wiki/More_(command)) that MS ported to DOS (and still exists in unix today). Later, `less` was written for unix, but MS never ported that, unfortunately. – wisbucky Jan 13 '17 at 02:17
  • less is much better than more, for example it allows you to scroll and search through the text – Constantino Cronemberger Dec 07 '18 at 11:43
5

I just use the GOW version of less, works fine.

Dauchande
  • 106
  • 1
  • 4
2

to get grep/vim/wget and other Linux like commands in powershell I suggest running.

iex (new-object net.webclient).downloadstring(‘https://get.scoop.sh’)

then

scoop install grep
scoop install perl
scoop install vim

and to get a list of all of them

scoop search
ChadJPetersen
  • 383
  • 3
  • 17
2

I don't know of any direct analogue for less in powershell that you can implement easily. Your best bet is to get a windows implementation of less that is outside of cygwin, that way you can just drop in the binary somewhere accessible to your account.

zdan
  • 28,667
  • 7
  • 60
  • 71
1

In Windows 10 PowerShell + Cygwin I use:

gc .\myfile.log | less

Previously I was trying to use cygwin directly:

less .\myfile.log

but it shows binary file because of invalid charset setting between 32b-bit and 64-bit.

Harun
  • 667
  • 7
  • 13
0

I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et

In the case you missed this question (top voted) you might enjoy this answer.

Community
  • 1
  • 1
Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67