Find and find Functions

Source: Internet
Author: User

Find and find Functions
Syntax: find [path] [parameter] [action]

  • -Name filename: Find the file named filename.
  • -Iname filename: searches for the file named filename, but it is case insensitive.
  • -User username: searches for files whose owner is username.
  • -Group groupname: Find the file whose group is groupname.
  • -Nogroup: Find the file with no valid group, that is, the file group does not exist in/etc/groups.
  • -Nouser: Find the file with no valid owner, that is, the file owner is not stored in/etc/passwd.
  • -Uid: search by uid
  • -Gid: search by gid
  • -Mtime + n/-n: file with a write time greater than/less than n days
  • -Mmin + n/-n: a file with a write time greater than/less than n minutes
  • -Atime + n/-n: access or file execution time greater than/less than n days
  • -Amin + n/-n: access or file execution time greater than/less than n minutes
  • -Ctime + n/-n: files whose inode attributes (such as owner, permission, or link) are written or modified at a time greater than/less than n days
  • -Cmin + n/-n: files whose inode attributes (such as owner, permission, or link) are written or modified at a time greater than/less than n minutes
  • -Type B/d/c/p/l/f/s: block device, directory, character device, pipeline, symbolic link, common file, socket File
  • -Size + n/-n [bmc], search by file size
  • -Perm: search by execution permission
  • -Prune: ignore a directory.
  • -A connects two different conditions, but both conditions must be met at the same time.
  • -O connects two different conditions, and one of the two conditions can be satisfied.
  • -Not: returns the inverse of the condition.
  Example:

-Perm

# Find/tmp-perm 755 // find the file whose permission is 755 in the/tmp directory

# Find/tmp-perm + 222 // indicates that only the write permission of a user (owner, group, or other) can be matched.

# Find/tmp-perm-222 // indicates that all types of users must have the write permission.

-Size

# Find/tmp-size 2 M // find the file that is equal to 2 M in the/tmp directory
# Find/tmp-size + 2 M // search for files larger than 2 M in the/tmp directory # find/tmp-size-2 M // search for files smaller than 2 M in the/tmp directory file
Find the executed action

#-Print // default action

#-Ls // use ls to display it after searching

#-OK [commend] // query whether the user wants to execute the command after the command is executed

#-Exec [commend] // run the command directly without asking the user when executing the command after searching

# Find/tmp-atime + 30-exec rm-rf {}\;#{} indicates the found File

# Find/tmp-name "*. php" | xargs chmod a + x

Specify multiple directories

# Find/etc/tmp/root-name passwd // directories are separated by Spaces

Use wildcards

*, 0 or multiple arbitrary characters

?, Any character

[], Any character in the brackets

-A,-o,-not

#find /tmp -name "*.php" -a -user root

#find /tmp -name "*.sql" -o user zhaoyn

#find /tmp -not -user root

Ignore specified directory

#find ./ -path "./server" -prune -o -name "*.log" -print

Ignore multiple directories

#find ./ \( -path "./server" -o -path "./test" \) -prune -o -name "*.log" -print

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.