Windows equivalent of the 'tail' command [duplicate]
Is there a way to simulate the *nix tail command on the Windows command line? I have a file and I want a way to snip off the first n lines of text. For example:
D:\>type file.txt
line one
line two
line three
D:\>*[call to tail]* > result.txt
D:\>type result.txt
line two
line three
IF you have Windows PowerShell installed (I think it's included since XP) you can just run from cmd.exe:
Head Command:
powershell -command "& {Get-Content *filename* -TotalCount *n*}"
Tail Command:
powershell -command "& {Get-Content *filename* | Select-Object -last *n*}"
or, directly from PowerShell:
Get-Content *filename* -TotalCount *n*
Get-Content *filename* | Select-Object -last *n*
update
PowerShell 3.0 (Windows 8 and higher) added Tail
command with alias Last
.
Head
and First
aliases to TotalCount
were also added.
So, commands can be re-written as
Get-Content *filename* -Head *n*
Get-Content *filename* -Tail *n*
No exact equivalent. However there exist a native DOS command "more" that has a +n option that will start outputting the file after the nth line:
DOS Prompt:
C:\>more +2 myfile.txt
The above command will output everything after the first 2 lines.
This is actually the inverse of Unix head:
Unix console:
root@server:~$ head -2 myfile.txt
The above command will print only the first 2 lines of the file.
more /e filename.txt P n
where n = the number of rows to display. Works fast and is exactly like head
command.