Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

20. Files and Directories > Monitor a File for Changes

Monitor a File for Changes

Problem

You want to monitor the end of a file for new content.

Solution

To monitor the end of a file for new content, use the -Wait parameter of the Get-Content cmdlet:

Get-Content log.txt -Wait

Discussion

The -Wait parameter of the Get-Content cmdlet acts much like the traditional Unix tail command with the --follow parameter. If you provide the -Wait parameter, the Get-Content cmdlet reads the content of the file but doesn’t exit. When a program appends new content to the end of the file, the Get-Content cmdlet returns that content and continues to wait.

Note

Unlike the Unix tail command, the Get-Content cmdlet does not support a feature to let you start reading from the end of a file. If you need to monitor the end of an extremely large file, a specialized file monitoring utility is a valid option.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint