Find command-Linux Log regular migration script

Source: Internet
Author: User
Find Command Format
find  pathname  --options  [-exec -print -ok ..]

Find Command Parameters

Pathname: directory path searched by the find command-print: find command outputs the matching file to the standard output-Exec: Find command to execute the shell command given by this parameter on the matching file. format: Command {}\;-OK: similar to the role of Exec

Find Command Options

-Name: search by file name-Perm: search by File Permission-user: search by file user master-group: search by file user group-type: find a type of file B -- block Device File d -- directory c -- character device file p -- pipeline file l -- symbolic link file f -- common file-mtime: find the file according to the file change time-n -- indicates that the file change time is less than N days + n -- indicates that the file change time is earlier than N days ago.

The log migration script uses the mtime parameter of the find command to migrate the log files two weeks ago to the specified directory. For more information, see

#! /Bin/bash #1. standard definition backup_dir = "/backup/log" keep_days = 14week_num = 'date + % W' flag = 'expr $ week_num % 2' #2. you need to migrate the directory test1 = "/var/log/nginx/test1" migrate_dir = ($ test1) #3. perform the migration backup once every two weeks if [$ flag-EQ 1]; thenfor dir in $ {clean_dir [*]} doif [-d $ dir]; then # Build the migration directory if [! -D $ backup_dir $ dir]; thenmkdir-p $ backup_dir $ dirfi # file migration for file in 'Find $ Dir-type F-mtime + $ keep_days-exec ls {}\; 'domv $ File $ backup_dir $ dirdonefidonefi

Crontab executes the log migration script every two weeks.

# Regular log migration script 0 4 ** 7/2/home/wangzhengyi/scripts/clean-scripts/migrate. Sh

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.