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
Search by file name
Find by file permissions
Search by file Owner
Find by file genus Group
Find a file without a valid owner, that is, the genus of the file does not exist in the/etc/groups
#查找无有效属组的文件, that is, the owner of the file does not exist in the/etc/groups
Find files by file change time,-n refers to n days (minutes), +n refers to n days (minutes) before
By file access time to find files,-n refers to n days (minutes), +n refers to n days (minutes) ago
Find files by file creation time,-n refers to n days (minutes), +n refers to n days (minutes) before
Look for change times newer than F1 but older than F2 files
Find block devices, directories, character devices, pipelines, symbolic links, plain files
Check for files with a length of n blocks [or n bytes]
Find files in a type of file system that are typically found in/etc/fstab
Do not cross file system mount points when checking files
If you encounter a symbolic link file, follow the file that the link refers to
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
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.
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
# find./-atime 0
# 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