读取文件的最后20个字节

1 powershell cmd

在一个最后20个字节的图像文件中,我需要检索一个校验和.我查看了Get-Content命令.有没有办法扭转读数,使其从文件的末尾开始?如果不是,是否还有其他命令可用于读取文件的最后20个字节?

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-6

Joe*_*oey 6

您可以将Get-Commands -Tail参数与参数Byte值结合使用-Encoding:

$bytes = Get-Content myFile -Tail 20 -Encoding Byte
Run Code Online (Sandbox Code Playgroud)

与文档相反,-Tail并不总是在行上行动.

  • 鉴于[PSv6](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-6)不再支持`-Encoding Byte`,而是`-AsByteStream`参数 (2认同)