Find a tool for Linux files non-find Mo genus

Source: Internet
Author: User
Tags touch command

Yesterday I saw a group of friends discussing the find command in many groups, so today I'll talk to you about the use of the Find command in work:


First, find syntax

Usage: Find PATHNAME [-option] [-exec|-ok command] {} \;

    • PATHNAME: path name to find

    • [option]: selectable parameters to match

    • [-EXEC|-OK command]: command operation of files to be found

    • {}: File name found

    • \;: backslash represents escape, semicolon represents Terminator

Second, find parameters

    • -name

Search by file name
    • -perm

Find by file permissions
    • -user

Search by file Owner
    • -group

Find by file genus Group
    • -nouser

Find a file without a valid owner, that is, the genus of the file does not exist in the/etc/groups
    • -nogroup

#查找无有效属组的文件, that is, the owner of the file does not exist in the/etc/groups

    • -mtime (mmin)-N +n

Find files by file change time,-n refers to n days (minutes), +n refers to n days (minutes) before
    • -atime (Amin)-N +n

By file access time to find files,-n refers to n days (minutes), +n refers to n days (minutes) ago
    • -ctime (Cmin)-N +n

Find files by file creation time,-n refers to n days (minutes), +n refers to n days (minutes) before
    • -never F1!F2

Look for change times newer than F1 but older than F2 files
    • -type [b| d| c| p| l| F]

Find block devices, directories, character devices, pipelines, symbolic links, plain files
    • -size N[c]

Check for files with a length of n blocks [or n bytes]
    • -depth

Find files in a type of file system that are typically found in/etc/fstab
    • -mount

Do not cross file system mount points when checking files
    • -follow

If you encounter a symbolic link file, follow the file that the link refers to
    • -prune

Ignoring a directory, if the-depth option is used at the same time, the-prune option is ignored by the Find command.

Third, find case list

1. Find files larger than 300M in the specified directory and move them to the specified path

# Find ~-size +300m# Find ~-size +300m-exec mv {} ~/sql/\;

2. Find files larger than 300M in the specified directory and delete them in two ways

# Find/-size +300m-delete# Find/-size +300m-exec rm-rf {} \;

3. Find files larger than 1G and less than 1.5G in the specified directory

# Find/-size +1g-size-1.5g

4. Two ways to find files that end in a specified directory other than. sh

# Find/-not-name ' *.sh ' # find./! -name ' *.sh '

5. Delete the backup file for the database 7 days ago

# find/bakcup/-type f-name ' *.sql '-mtime +7-exec rm-rf {} \;

6. Find files ending in. sh in the current directory, but exclude subdirectories as files in the script directory

# Find. -path './script '-prune-o-name ' *.sh '

7. Find the file that ends with. py in the current directory and modify it to. PYc

# Find/-name ' *.py '-exec mv {} ' {}c ' \;

8. Find all the files in the current directory and replace the Hello string in the file with Hello

# echo ' Hello world! ' > test01.txt# echo ' Hello teacher! ' > test02.txt# find./-type f-exec sed-i ' [Email protect Ed]@[email protected] ' {} \;

Iv. Find collocation Log Highlights

    • 1. Time Search

Atime (Access Time): The duration of the visit, the last event read by the file, and the current time can be changed using the Touch command

CTime: Change time, refers to the last event of the file itself changed, change action is chmod, CHGRP, MV, etc.

Mtime (Modify time): Modification times, refers to the file content last modified event, modify the action echo redirect, VIM, etc.

    • 2. Time syntax

Find PathName {-atime/-ctime/-mtime/-amin/-cmin/-mmin} [-/+]num

First parameter: Find the path name of a file

The second parameter: the preceding letters A, C, and m respectively indicate access, change, modification; time is the date, Min is the minute

The third parameter: should not be signed to indicate that it is worth, '-' within the expression, ' + ' represents the previous

    • 3, Time small exercise

    • Find files that have been visited in the current directory: Time Unit is day

# find./-atime 0
    • Find files in the current directory that have been modified within 10 minutes from the moment 5 minutes ago: min

# Find./-mmin-10-min +5
    • In addition an additional command :xargs

    • The use of this command is similar to the exec parameter of find, such as:

# Find./-type F | Xargs chmod 755# Find./-type F | Xargs echo ' >/root/filename.log# Find/-type F | Xargs RM-RF

An article on the Web:

The event algorithm for find Mtime: http://www.oracleblog.org/study-note/how-to-calculate-find-mtime/

This article is from the "Zheng" blog, make sure to keep this source http://467754239.blog.51cto.com/4878013/1620000

Find a tool for Linux files non-find Mo genus

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.