Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to display the first 50 lines of the output of a command (any command). In other words, I essentially want an equivalent of the Unix "head" command.

but I dont have permission to create file using the command :

C:> netstat -an > temp.txt && for /l %l in (1,1,10) do @for /f "tokens=1,2* delims=:" %a in ('findstr /n /r "^" temp.txt ^| findstr /r "^%l:"') do @echo %b

Since the command executes on a remote server it does not allow creation of files, please help me change this command to pipe with another command.

I am working on a getting a list of only 50 files that have a specific file name pattern e.g. taha_12345_T_T_00987.txt from a specific folder.

share|improve this question
I don't have an answer for you, but my first google search popped this up as the first hit: Windows equiv of the 'head' command. There are several suggestions listed there. – yoonix Oct 1 '13 at 19:58
Thanks yoonix, my question is inspired from the question in that link, i need a more specific anwer to my question. – taha Oct 1 '13 at 20:39

Do you have access to PowerShell? It is usually available starting with XP/Server 2003.

PS C:\netstat -an | select -first 50
share|improve this answer
it is a leagcy application which requires changes, I cannot choose powershell over dos commands , I just need to filter the list to only 50 files at a time from a folder that may contain hundreds of files that is causing the script to stall/hang and does not even respond with an error message. – taha Oct 1 '13 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.