To delete the backup file in the system, run the following command: # find/tmp-mtime + 30-typef-name *. sh [AB]-execrm-f {}\; if files of the last 30 days are retained in a directory, files of the last 30 days are automatically deleted # find/tm...
To delete the backup file in the system, run the following command: # find/tmp-mtime + 30-type f-name *. sh [AB]-exec rm-f {}\; if the files of the last 30 days are retained in a directory, files deleted 30 days ago # find/tmp-mtime + 30-type f-name *. sh [AB]-exec rm-f {}\;/tmp -- set the directory to be searched;-mtime + 30 -- set the time to 30 days ago; -type f -- set the search type to file;-name *. sh [AB] -- set the file name to contain sha or shb;-exec rm-f -- delete the file after the search is completed. the prompt is: after writing this command to crontab, you can automatically find and delete the job. Other methods are similar # find. -mtime + 30-type f | xargs rm-rf www.2cto.com My operation is: first ls-ltr to view the time, not too long, so use-cmin n to find the last N minutes in the system file status changed. Specific command: $ find/home/oracle/test6-cmin + 20-type f-name *. xml-exec rm-f {}\; other methods are similar # find. -mtime + 30-type f | xargs rm-rf $ find. -type f-cmin + 10-exec rm-rf *. xml {} \; find. type f-name "debug *"-atime + 3-exec rm-f {}\; first, enter the cd Directory: find. -name "*~ "-Exec rm {}\; find. -ctime + n-exec rm-vi {}\; here + n refers to how many days ago, such as: + 7 find. -ctime + 7-exec rm-vi {}\; if you do not want to manually confirm it, change-vi in the command to-fv for details. the difference between atime, ctime, and mtime must be clearly distinguished when you use find. generally, mtime is used for search, because the mtime timestamp is displayed in ls-al. you can use the following: # find $ PAHT-mtime + 3-OK rm {}\; delete comparison insurance in interactive mode. 1. name the file according to a certain date format 1. output date according to a certain format: www.2cto.com date + "% y % m % d" Format Description: %: printed % n: next line % t: hop % H: Hour (00-23) % I: Hour (01-12) % k: Hour (0-23) % l: hour (1-12) % M: minute (00-59) % p: Display Local AM or PM % r: direct display time (in 12-hour format: hh: mm: ss [AP] M) % s: seconds from January 1, 1970 00:00:00 UTC till now % S: Seconds (00-60) % T: direct display time (in 24-hour format) % X: equivalent to % H: % M: % S % Z: Display time zone
Date: % a: Day of the week (Sun-Sat) % A: Day of the week (Sunday-Saturday) % B: Month (Jan-Dec) % B: month (January-December) % c: Date and time % d: Day (01-31) % D: Date (mm/dd/yy) % h: same as % B % j: Day of the year (001-366) % m: Month (01-12) % U: Week of the year (00-53) (The first day of a week with Sunday) % w: Day of the week (0-6) % W: Week of the year (00-53) (Monday is the first day of a week) % x: displays the date (mm/dd/yy) % y: The last two digits of the year (00.99) % Y: full year (0000-9999) 2. name the file with a date: filename 'date + % y % m % d'. here, "'" is not a single Quotation marks. 2. delete the file www.2cto.com based on the file creation date. 1. run the find command to find pathname-options [-print-exec-OK...]. pathname: directory path searched by the find command. For example, use "." to represent the current directory, and use "/" to represent the root directory of the system. -Print: The find command outputs matching files to the standard output. -Exec: The find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form of 'command' {}\;. note the space between {} and. -OK: the role of-exec is the same, but the shell command given by this parameter is executed in a safer mode. a prompt is displayed before each command is executed, let the user determine whether to execute. Options:-name: searches for files by file name. -Perm searches for files based on the file permissions. -Prune uses this option to make the find command not to be searched in the specified directory. if The-depth option is used at the same time,-prune will be ignored by the find command. -The user searches for files based on the file owner. -The group searches for files based on the group to which the files belong. -Mtime-n + n: find the file based on the file change time.-n indicates that the file change time is earlier than n days, and + n indicates that the file change time is earlier than n days. The find Command also has the-atime and-ctime options, but they both have the-m time options. -Nogroup: find the file with no valid group, that is, the group to which the file belongs does not exist in/etc/groups. -Nouser: find the file without a valid owner, that is, the owner of the file does not exist in/etc/passwd. -Newer file1! File2 www.2cto.com searches for files whose change time is newer than file1 but older than file2. -Type: search for a certain type of files, such as B-block device files. D-directory. C-character device file. P-MPs queue file. L-symbolic link file. F-common file. -Size n: [c] searches for files with a length of n blocks. if a file contains c, the file length is measured in bytes. -Depth: When searching for a file, first find the file in the current directory and then find it in its subdirectory. -Fstype: searches for files in a certain type of file system. These file system types can usually be found in the configuration file/etc/fstab, this configuration file contains information about the file system in the system. -Mount: The mount point of the file system is not crossed during file search. -Follow: If the find command encounters a symbolic link file, it will trace the file to which the link points. -Cpio: Use the cpio command to back up the files to the tape device. Time-related parameters are supplemented as follows: -amin n: find the files accessed in the last N minutes in the system-atime n: Search for the files accessed in the last n * 24 hours in the system www.2cto.com-cmin n: find the files changed in the last N minutes in the system. FILE-ctime n search for files in the system that were changed in the last n * 24 hours-mmin n search for files in the system that were changed in the last N minutes-mtime n search system last n * 24 hours file data changed 2. delete the file before the fixed date find logs-type f-mtime + 5-exec rm {}\;
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