Windows 等效于“head -c”命令

pla*_*a33 16 windows command-line

我有一个执行以下操作的 unix 命令:

head -c 2048 > test.txt
Run Code Online (Sandbox Code Playgroud)

基本上它占用了 test.txt 文件的前 2kb。

我们可以在 windows cmd 提示符下做类似的事情吗?

son*_*njz 17

由于@chubbsondubs 的评论,简化了这个答案。

-TotalCount如果读取文本,将计算行数,因此始终强制它以字节形式读取文件,然后-TotalCount将仅引用字节,您可以获得帐户计数。

Get-Content test.txt -Encoding byte -TotalCount 2KB | Set-Content test1.txt -Encoding byte
Run Code Online (Sandbox Code Playgroud)

更多信息:https : //stackoverflow.com/questions/888063/powershell-to-get-the-first-x-mb-of-a-file