The use of the Find name order in Linux

Source: Internet
Author: User
Tags modifier

use of the Find command:

Definition: Perform a real-time search on the local file system to find files that match the conditions of the command line parameters.

Use format: Find target file match option match parameter

The first argument to find is the directory to search for, and if the directory parameter is omitted, find starts the search in the current directory and finds a match in any subdirectory.

Find provides a number of options to accurately describe the type of file you should look for, and you can search by any combination of file name, file size, last modified timestamp, and other file attributes.

eg :

Find/-name Sshd_config search for files named Sshd_config in the root directory and all subdirectories

Find/-name ' *pass* ' search for files in the/etc directory that contain pass anywhere in the name

Find/-iname ' *messages* '-I indicates ignoring case

Find can search for files based on all permissions, at which point you can use -user,-group,-uid,-gid, and more

eg:

Find//home/student–user student finds files owned by student users in the/home/student directory

Find//home/student–group Student search for files owned by student group in /home/student directory

Find/-user Root–group Mail

-perm option to find files with a specific permission set

permissions can be preceded by a / or - sign, with /if the number permission will match the file's user, group, or other person in the permission set of at least one, with / or - when used,0 the value is similar to a wildcard character, which means "at least no content permission"

eg:

Find/home–perm 644 Matching user has read and Write permission, group member has reading permission, others have Read permission

find/home–perm-724 Matching user has at least Read and write Execute permission, group member at least write permission, others have at least Read permission

find–perm-004

Find command to find a file that matches the specified size by -size option plus numeric values and units to specify

n : Equal to n size

+n: Size greater than n

- n : Size less than n

units used with size are:K kilobytes M gigabyte G gigabytes

eg:

Find–size 10M Search for files of size 10M in the current directory

Find–size +10m Search for files larger than 10M in the current directory

find–size-10m search for files smaller than 10M in the current directory

The-size unit modifier takes all content up to one unit, such as find-size 1M, which displays files less than 1MB because it takes all files up to 1MB

The-type option restricts the search scope to the given file type, and the type has

F: Normal file

D: Catalogue

L: Soft links (Symbolic links)

B: Block device

eg

Find/etc–type F Search All common files in /etc directory

Find/etc–type d Search all directories in /etc folder

Find/etc-type l Search All symbolic links in the /etc directory

Find/dev–type b Search for a list of all devices in the /dev Directory

The-mmin option, plus the time in minutes, will search for all the files that were changed just in the past .

Similarly, there are -amin , -cmin

M means to modify modify,min for minutes,a for access, C to create

-mtime options are in days, similar to-ctime,-atime

eg:

Find/-mmin will search for files that are exactly five minutes from the modification time

Find/-mmin +200 will look for all files that were changed before a few minutes

Find/-mmin-150 will search for all files that are less than five minutes away from the modified time

The-links option Plus number will find all files with a specific number of hard links, and Suzi preceded by a + modifier will find the number of hard links more than the given number of files, if the number preceded by the ~ modifier, The search will be limited to the number of hard links that are less than the given number of all files.

eg

Find/-type f–links +1 searches for all normal files with hard links greater than 1 in the root directory

Complex usage: You can perform additional operations on the searched files

eg:

Find/usr/bin–size +50k–exec cp {}/tmp/bin \; Search All Files of size 50K under the/usr/bin/directory and copy them to the/tmp/bin directory

Find/usr/bin–type f–exec rm–rf {} \; Search for all normal files in the/usr/bin directory and perform a delete operation on it


The use of the Find name order in Linux

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.