Regular cleanup of files over a certain period of time under Windows

Source: Internet
Author: User

Regular cleanup of file backgrounds over a certain time under Windows

Linux when we want to regularly clean up more than 7 days without modification of the log or backup files, can be done by the following command:

Find $path-type f-mtime|-ctime +7-exec rm-f {} \;

windows looks far less powerful than Linux:

C:\documents and settings\qunyingliu>find /? Searches for a text string in a file or files. find [/v] [/c] [/n] [/i] [/off[line]]  "string"  [[drive:][path]filename[ &NBSP, ...]   /v         displays all lines not  containing the specified string.  /C          displays only the count of lines containing the string.   /n         displays line numbers with  the displayed lines.  /I          Ignores the case of characters when searching for the string.   /off[line] do not skip files with offline attribute set.   "string"    Specifies the text string to  find.  [drive:][path]filename              specifies a file or files to search. if a path is not specified, find searches the text typed  at the promptor piped from another command.

How to complete the time to clean up more than a certain period of file, is it really necessary to wait for the disk alarm after manual processing?

Find foreign aid, find helpmate.

As the saying goes, the development relies on Google, operation and maintenance by Baidu, let us also Google once, found a very useful Windows command line, Forfiles.

Help information for the forfiles command:
FORFILES [/P pathname] [/M searchmask] [/S]         [/C command] [/D [+ | -] {yyyy/MM/dd | dd}]

Describe:
Select a file (or a set of files) and execute a command on that file.

parameter list:

    /P    pathname       indicates the path to start the search. The default folder is the current work                           catalog   (.).     /M    searchmask     search for files based on the search mask. The default search mask is   ' * '.     /S                    guidance  forfiles  recursion to subdirectories. Like   "dir /s".     /C    command        Represents the command executed for each file. command string should be                           enclosed in double quotation marks.                           default command is   "CMD&NBsp;/c echo  @file ". The following variables                           can be used in the command string:                          @file      -  returns the file name.                           @fname    -  Returns the file name without an extension.                           @ext      -  returns only the file extension.                           @path     -  Returns the full path of the file.                          @relpath  -  Returns the relative path of the file.                           @isdir    -  If the file type is a directory, return   "TRUE";                                      if it is a file, return   "FALSE".                           @fsize    -  Returns the file size in bytes.                           @fdate    -  Returns the date the file was last modified.                          @ftime    -  Returns the time the file was last modified.                           to include special characters at the command line, use the characters  0xHH                          uses hexadecimal code (for example, 0x09  for  tab).                           Internal  CMD.exe  command should be preceded by   "CMD /C"   start.     /D    date            Select a file whose last modification date is greater than or equal to   (+),                          or less than or equal to   (-)   with   "yyyy/mm/ DD "  FormatThe specified date;                          or select a file whose last modification date is greater than or equal to   (+)                           Current date plus   "DD"   day, or less than or equal to   (-)   current                           date minus   "DD"   days. Valid   "DD"   days can be                Any number within the           0 - 32768  range. If you do not specify,                          "+"   is used as the default symbol.     /?                   displays this help message. 
Problem solving

According to the instructions of the forfiles file, we need to delete all the files in the X:\xxxx directory for more than 7 days, then the command is as follows:

forfiles/p x:\xxxx/s/C "cmd/c del @path"/d-7

Of course, because I want to delete the X:\xxxx no subdirectories, and do not need to keep, so found 7 days before the files can be deleted, if it is necessary to preserve subdirectories that will specify/m after the parameters, such as/M "*.sql" delete all found more than seven days of. SQL end of the file.

51cto blogs generally only record some operations, the editor does not support Markdown.

Welcome to Jane's book to listen to my bragging about the marathon life, Http://www.jianshu.com/users/0158c185ef40.

This article from "Ops said: from rookie to veteran" blog, please be sure to keep this source http://liuqunying.blog.51cto.com/3984207/1735614

Regular cleanup of files over a certain period of time under Windows

Related Article

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.