Windows Equivalent of the ‘head -c’ command

command linewindows

I have a unix command that does the following:

head -c 2048 > test.txt

basically its taking first 2kb of the test.txt file.

Can we do something similar in windows cmd prompt?

Best Answer

Simplifying this answer because of @chubbsondubs' comment.

-TotalCount will count lines if reading in text, so always force it to read the file as bytes, then the -TotalCount will only refer to bytes and you can get an account count.

Get-Content test.txt -Encoding byte -TotalCount 2KB | Set-Content test1.txt -Encoding byte

More information here: https://stackoverflow.com/questions/888063/powershell-to-get-the-first-x-mb-of-a-file