How to find files by modified time in PowerShell _powershell

Source: Internet
Author: User

This article describes a file-by-file modification time in a PowerShell to find files, using the LastWriteTime property of the file object.

In many cases, I need to find the files by the time I change them. For example, a website, recently found to be hanging horse, we may look at the recent backup has been modified, so as to determine the approximate time period of black. With this time period, we want to see what files have been modified within this period of time, what new files, it is likely that hackers left a word trojan, and even the big horse in the inside.

Let's look at how PowerShell can find files based on the file modification time.

Small series first to see what the D-packing directory under what content:

Copy Code code as follows:

PS c:\users\splaybow> dir d:
Table of Contents: D:\
Mode LastWriteTime Length Name
----                -------------     ------ ----
D----2013/11/1 22:27 Green
D----2013/11/4 17:31 program Files
D----2013/11/6 10:23 program Files (x86)
D----2013/10/13 10:02 soft

Because the small series does not use the-recurse parameter, there is no looping list of subdirectories. If we look up all the files in a directory, we should take this parameter after dir. Now get altogether is four directories. All right, let's sift through the change time before 2013-11-4 file (or directory). Note that the following command uses the pipe to filter the directories listed by Dir to find out if the lastwritetime is less than 2013-11-4, and if it is less than, it must not be included. The results were as follows:
Copy Code code as follows:

PS c:\users\splaybow> dir d: |? {$_.lastwritetime-lt ' 2013-11-4 '}
Table of Contents: D:\
Mode LastWriteTime Length Name
----                -------------     ------ ----
D----2013/11/1 22:27 Green
D----2013/10/13 10:02 soft

Although I just search the directory by the time, but for the file, operation or command is actually exactly the same. So you can rest assured that this command is used to search for files of a specified time period.

About PowerShell according to the modified time to find files, this article on the introduction so much, I hope to help you, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.