windows 如何从 powershell 控制台查看日志文件?(即powershell相当于'less')
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6073431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I view a log file from powershell console ? (i.e. powershell equivalent of 'less')
提问by user331465
What is the powershell equivalent of 'less'?
'less' 的 powershell 等价物是什么?
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.
我寻找一个寻呼机(相当于“less”),它允许搜索(匹配或忽略大小写)、一次多个文件等。
Some of our servers run windows 2008 and I lack admin privileges to install cygwin
我们的一些服务器运行 Windows 2008,我缺乏安装 cygwin 的管理员权限
I had heard windows 2008, MSFT got their act together and provided some easy-for-admins tools.
我听说过 Windows 2008,MSFT 联合起来并提供了一些易于管理员使用的工具。
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.
- 我对电源外壳知之甚少
- 新服务器上有 2008
- 虽然我喜欢过去的许多工具,但 dos 提示不是其中之一
- 我希望 Powershell 具有相当于 grep、ls、less、xargs 等的功能
- 我知道 powershell 为我们提供了这些工具
- 我很快就提出了我的问题。
thanks
谢谢
采纳答案by Matt
It reads like you know you can do this:
它读起来就像你知道你可以这样做:
gc logfile.log | more
gc 日志文件.log | 更多的
(GC is an alias for Get-Content).
(GC 是 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).
(Get-Help gc 也能正常工作)。
And the bits you may be interested in are limit\filter etc...
您可能感兴趣的位是限制\过滤器等...
Get-Help gc -Parameter * | more
Get-Help gc -Parameter * | 更多的
回答by ChadJPetersen
to get grep/vim/wget and other Linux like commands in powershell I suggest running.
要在 powershell 中获取 grep/vim/wget 和其他类似 Linux 的命令,我建议运行。
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
回答by zdan
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.
我不知道在 powershell 中可以轻松实现的任何直接模拟。您最好的选择是在 cygwin 之外获得less的 Windows 实现,这样您就可以将二进制文件放入您的帐户可访问的某个地方。
回答by Harun
In Windows 10 PowerShell + Cygwin I use:
在 Windows 10 PowerShell + Cygwin 中,我使用:
gc .\myfile.log | less
Previously I was trying to use cygwin directly:
以前我试图直接使用 cygwin:
less .\myfile.log
but it shows binary file because of invalid charset setting between 32b-bit and 64-bit.
但它显示二进制文件,因为 32b 位和 64 位之间的字符集设置无效。