Linux Find command detailed

Source: Internet
Author: User

Usage

  Find [path] Content

Parameters

The-print:find command outputs the matched file 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 \;

Find-exec RM-RF {} \; Delete the found files
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.

[[email protected] test]# find-ok rm-rf {} \;
< RM .... >? Y first ask before deleting

-depth: #使查找在进入子目录前先行查找完本目录

-MAXDEPTH Specifies the maximum number of layers to find

Find-maxdepth 1 does not find subdirectories in the current directory

Find-maxdepth 2 Find only the first level directory under the current directory

Find by file name

-name supports wildcard characters

Find files ending with ". Sh"
Find ' *.sh ' . /tar. SH

Find by file time stamp

  -mtime-n +n #按文件更改时间来查找文件,-n means n days or less, +n means n days ago

-atime-n +n #按文件访问时间来查

-ctime-n +n #按文件创建时间来查找文件,-n means n days or less, +n means n days ago

  -mmin-n +n #按文件更改时间来查找文件,-n means less than n minutes, +n means n minutes ago

-amin-n +n #按文件访问时间来查

-cmin-n +n #按文件创建时间来查找文件,-n means less than n minutes, +n means n minutes ago

[[email protected] ~]# find-cmin-4   Find the file created within 4 minutes. /hhh[[email protected] ~]# find-ctime +3   

Find by File type

  -type d/l/b/c/f/s

[[email protected] ~]# find-maxdepth 1-type d see which folders are in the current directory
.
./test
./.subversion
[Email protected] ~]#

According to the owner of the file, belong to group search

-nogroup #查无有效属组的文件 that the genus of the file does not exist in the/etc/groups
-nouser #查无有效属主的文件, that is, the owner of the file does not exist in the/etc/passwd

-user username #按文件属主来查找
-group GroupName #按组来查找

Find by file permissions

  -perm

[Email protected] ~]# find-perm 600-exec ls-l {} \; Finds files with permission 600 under the current file and displays them in a long format
-RW-------1 root root 49 11? 3 18:57./.lesshst
-RW-------. 1 root root 21820 11? 3 16:22./.bash_history
-RW-------1 root root 19599 11? 1 01:38./.mysql_history
-RW-------1 root root 5125 11? 3 00:18./.viminfo
-RW-------. 1 root root 1087 6? 21:14./anaconda-ks.cfg
[Email protected] ~]#

Find by File size

  -size [-/+]n

' B ' for 512-byte blocks (the "the default if no suffix is used)

' C ' for bytes

' W ' for two-byte words

' K ' for kilobytes (units of 1024x768 bytes)

' M ' for megabytes (units of 1048576 bytes)

' G ' for gigabytes (units of 1073741824 bytes)

[Email protected] ~]# find-size +20000c    
[[email protected] ~]# find-size 20000c    Find just 20000c bytes of file
[[email protected] ~]# find-size-20000c   find files less than 20000c bytes

Exclude a directory when looking for

find/root/-path "/root/test"-prune-o-print Find files in/root/test directory except/root directory

Exclude a certain type of file when searching

  “! "Denotes non-

Find 1 " \.* "   displays files that are not hidden properties. /test. /HHH. /Install. Log. /EOF. /test2. /anaconda-ks.cfg. /Install. Log.syslog. /tar. SH

Linux Find command detailed

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.