Windows: PowerShell `Tail`, & `Head` Equivalents
source link: https://www.shellhacks.com/windows-powershell-tail-head-equivalents/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Windows: PowerShell `Tail`, & `Head` Equivalents
The tail
and head
are two of the most commonly used commands for displaying the contents of a file in Linux.
Windows PowerShell, in its turn, also has equivalents of the Linux tail
and head
commands.
From this short post you will learn how to use the equivalents of the tail
and head
commands in Windows PowerShell and how to dynamically print a file’s contents, i.e. follow it like using tail -f
.
Cool Tip: Windows watch
command equivalent in CMD and PowerShell! Read more →
Tail and Head Commands in Windows PowerShell
PowerShell Tail Command
To tail
the output of a PowerShell command in Windows, execute:
PS C:\> <command>| Select -Last <numberOfLines> - example - PS C:\> systeminfo | Select -Last 10
To print the last few number of lines of a file in Windows, use a combination of the PowerShell Get-Content
command with the -Tail
option:
PS C:\> Get-Content <fileName> -Tail <numberOfLines> - example - PS C:\> Get-Content "C:\Logs\AppLog.txt" -Tail 10
A -Wait
option of the Get-Content
command in PowerShell is an equivalent of tail -f
on Linux systems:
PS C:\> Get-Content <fileName> -Wait - example - PS C:\> Get-Content "C:\Logs\AppLog.txt" -Wait
The same as tail -f
on Linux, the above command will print the contents of a file and then will continue printing lines as they are added to the file unless it is interrupted with, for example, Ctrl + C keystroke.
PowerShell Head Command
To print a head
of the output of a PowerShell command in Windows, execute:
PS C:\> <command>| Select -First <numberOfLines> - example - PS C:\> systeminfo | Select -First 10
To print the first few number of lines of a file in Windows, use a combination of the PowerShell Get-Content
command with the -Head
option:
PS C:\> Get-Content <fileName> -Head <numberOfLines> - example - PS C:\> Get-Content "C:\Logs\AppLog.txt" -Head 10
Cool Tip: Windows touch
command equivalent in CMD and PowerShell! Read more →
Recommend
-
34
Although Python and JavaScript are quite different languages, there are some analogies which full s...
-
8
laminas-zendframework-bridge This library provides a custom autoloader that aliases legacy Zend Framework, Apigility, and Expressive classes to their replacements under the Laminas Project. This package should be installed onl...
-
4
Ever regretted opening a huge file? Don’t worry. The head and tail commands can be used...
-
5
Are there C ++ equivalents for I / O functions delimited by Buffers in Java? advertisements I'm trying to read / write multiple Protocol Buffe...
-
8
Change Computer Name – Windows CMD & PowerShell To show a computer’s name in Windows, simply execute the hostname command from a Windows command prompt (CMD) or PowerShell. There...
-
5
Windows: Get a User’s SID – CMD & PowerShell Any user, group or computer in Windows has a unique SID (security identifier) assigned. The SIDs are used to control access to various Windows resources like fi...
-
5
Ask HN: I miss Usenet. Are there any modern equivalents?
-
3
Saksham_Sahgal's blog Help fo...
-
2
Windows equivalents for common Mac dev tools I am about to start a new software engineering position where most folks have Windows machines. I’ve been using a Mac for development and Linux for deployment for...
-
3
Comparing Laptop Graphics Cards to Their Desktop EquivalentsComparing Laptop Graphics Cards to Their Desktop EquivalentsApril 1st 20...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK