Find command Mtime parameters and usage in Linux

Source: Internet
Author: User


When you use the Mtime parameter in the Find command, you will see the official explanation as follows:

-mtime N
File ' s data is last modified n*24 hours ago. The comments For-atime to understand how rounding affects the

Interpretation of the file modification times.

But in the use of a variety of reference useful + number,-number, no symbolic use, then what is the difference here?

Notice here N, if n is a value with the + number, delete n days ago All files, such as n=+1 and today is number 15th, then delete the previous data 14th, excluding 14th, if the minus sign (n=-1) to delete a day of files, such as today 15th, then delete 15th data, If it is (n=-2), the representative deletes all the data from the day before today, such as number 15th today, and then deletes it from number 14th. If you do not have a symbol, then delete the date specified in the first n days of the day, for example (N=1) and today is number 15th, then delete the number 14th on this day.

Note that the day here refers to the current system time, not 0-24 hours a day.


find Path-option [-print] [-exec-ok command] {};
The parameters of the Find command;

The directory path that the Pathname:find command looks for. For example, to represent the current directory, with/to represent the system root directory.
The-print:find command outputs matching files to the standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {};, note the space between {} and;
-ok: The same as the-exec, but in a more secure mode to execute the shell command given by this parameter, before executing each command, will be prompted to let the user determine whether to execute.

#-print to output the found file to standard output
#-exec command {}; -– will find the file to execute command operation, {} and; there are spaces between
#-ok and-exec are the same, except to consult the user before the operation
Example: Find. -name SVN | Xargs RM-RF
====================================================

-name filename #查找名为filename的文件
-perm #按执行权限来查找
-user username #按文件属主来查找
-group GroupName #按组来查找
-mtime-n +n #按文件更改时间来查找文件,-n refers to n days, +n refers to n days ago
-atime-n +n #按文件访问时间来查GIN: 0px ">

-ctime-n +n #按文件创建时间来查找文件,-n refers to n days, +n refers to n days ago

-nogroup #查无有效属组的文件, that is, the group of files does not exist in/etc/groups
-nouser #查无有效属主的文件, that the owner of the document does not exist in the/etc/passwd
-newer F1!f2 Find files,-n refers to the nth days, +n refers to n days ago
-ctime-n +n #按文件创建时间来查找文件,-n refers to n days, +n refers to n days ago
-nogroup #查无有效属组的文件, that is, the group of files does not exist in/etc/groups
-nouser #查无有效属主的文件, that the owner of the document does not exist in the/etc/passwd
-newer F1!F2 #查更改时间比f1新但比f2旧的文件
-type b/d/c/p/l/f #查是块设备, directories, character devices, pipelines, symbolic links, normal files
-size N[c] #查长度为n块 [or N-byte] files
-depth #使查找在进入子目录前先行查找完本目录
-fstype #查更改时间比f1新但比f2旧的文件
-type b/d/c/p/l/f #查是块设备, directories, character devices, pipelines, symbolic links, normal files
-size N[c] #查长度为n块 [or N-byte] files
-depth #使查找在进入子目录前先行查找完本目录
-fstype #查位于某一类型文件系统中的文件, these file system types can usually be found in/etc/fstab
-mount #查文件时不跨越文件系统mount点
-follow #如果遇到符号链接文件, track the file that the link refers to
-cpio%; #查位于某一类型文件系统中的文件, these file system types can usually be found in/etc/fstab
-mount #查文件时不跨越文件系统mount点
-follow #如果遇到符号链接文件, track the file that the link refers to
-cpio #对匹配的文件使用cpio命令, back them up to tape devices
-prune #忽略某个目录

=====================================================
$find    ~  -name   "*. TXT   -print    the. txt file in $HOME #在 and displays the
$find    .   -name    "*.txt"   -print
$find    .   -name   "[a-z]*"   - print   #查以大写字母开头的文件
$find   /etc  -name   "host*"   -print Check the file at the beginning of host
$find    .  -name   "[A-z][a-z][0–9][0–9].txt"    - print   #查以两个小写字母和两个数字开头的txt文件
$find .  -perm   755  -print
$find    .  -perm-007  -exec ls-l {};   #查所有用户都可读写执行的文件同-perm 777
$find  & nbsp;. -type d  -print
$find    .  !  -type   d  ,-print
$find    .  -type l  -print

$find    .  -size   +1000000c  -print         #查长度大于1Mb的文件
$find    .  -size   100c         -print       100c file
$find    .  - size   +10  -print               #查长度超过期作废10块的文件 (1 block = 512 bytes)

$CD/
$find etc Home Apps-depth-print | Cpio-ivcdc65536-o/dev/rmt0
$find/etc-name "passwd*"-exec grep "Cnscn" {}; #看是否存在cnscn用户
$find. -name "yao*" | Xargs file
$find.   -name "yao*" | Xargs echo "" >/tmp/core.log
$find. -name "yao*" | Xargs chmod o-w

======================================================

Find-name april* Find files starting with April in the current directory
Find-name april* Fprint file finds files starting with April in the current directory, and outputs the results into file
Find-name ap*-o-name may* Find files that start with AP or May
Find/mnt-name Tom.txt-ftype vfat Find files under/mnt with name tom.txt and file system type VFAT
Find/mnt-name T.txt! -ftype vfat find files under/mnt with name tom.txt and file system type not VFAT
Find/tmp-name wa*-type L in/tmp looks for a file named WA with a type of symbolic link
Find/home-mtime-2, check the files that were changed in the last two days under/home.
Find/home-atime-1 check for files accessed within 1 days.
Find/home-mmin +60, check the files that were changed 60 minutes ago in/home.
Find/home-amin +30, check for files accessed last 30 minutes ago.
Find/home-newer tmp.txt a file or directory that is newer than tmp.txt in/home
Find/home-anewer tmp.txt a file or directory near/home for access time than Tmp.txt
Find/home-used-2 lists files or directories that have been accessed within 2nd after a file or directory has been altered
Find/home-user CNSCN lists files or directories within the/home directory that belong to the user Cnscn
Find/home-uid +501 lists files or directories within the/home directory that have a user ID greater than 501
Find/home-group CNSCN lists files or directories within the/home group as CNSCN
Find/home-gid 501 lists files or directories in/home with a group ID of 501
Find/home-nouser lists files or directories within/home that are not part of the local user
Find/home-nogroup lists files or directories within/home that are not part of the local group
Find/home-name tmp.txt-maxdepth 4 lists Tmp.txt in/home with a maximum depth of 3 layers
Find/home-name tmp.txt-mindepth 3, starting on the 2nd floor.
Find/home-empty find files or empty directories of size 0
Find/home-size +512k check for files larger than 512k
find/home-size-512k check for files less than 512k
Find/home-links +2 Check for files or directories with a hard connection number greater than 2
Find/home-perm 0700 Search for files or directories with permission of 700
Find/tmp-name tmp.txt-exec Cat {};
Find/tmp-name Tmp.txt-ok rm {};

find   /  -amin    -10     # Find files accessed in the last 10 minutes of the system
find   /  -atime   -2        # Find files accessed in the last 48 hours of the system
find   /  -empty              find files or folders that are empty in the system
find   /  -group   cat         find files that belong to Groupcat in the system
find   /  -mmin    -5         # Find files that have been modified in the last 5 minutes of the system
find   /   -mtime   -1       #查找在系统中最后24小时里修改过的文件
find   /   -nouser           #查找在系统中属于作废用户的文件
find    /  -user    fred     #查找在系统中属于FRED这个用户的文件

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.