Linux file Find command application for find

Source: Internet
Author: User

In Linux, the common commands for file lookups are locate and find

Locate works: Global lookup, according to the system file database lookup, the database will be automatically generated during the same run for a period of time, provided that the Mlocate package is installed.

The Mlocate package installation generates the Locate command and the UpdateDB command, which is the command used to manually generate the database used to locate find files, which by default is/var/lib/mlocate/ Mlocate.db, an important file generated by the Mlocate package is/etc/cron.daily/mlocate.cron (script), which calls the update command in the scripts to achieve the Task Scheduler The purpose of establishing this database automatically

So, since locate is a database-based lookup, locate is characterized by fast speed and, like grep, a fuzzy lookup (greedy mode)


The Find:find command performs an exact lookup and supports a wide range of lookup criteria, requiring you to specify which directory to look for (not specifying the default is the current directory), but is slow because you need to traverse all the files in the directory

Use format for the Find command: Find directory pattern action

Directory indicates under which directories to look for

Pattern is used to specify the lookup criteria

Action is used to specify what to do with the found content (default to print to screen)

Pattern

1. Find-type character by file type

Character value: D for the directory file, F for the generic file, L for the linked file, s for the socket file, p for pipe files, etc. 2. Find-perm MODE based on file permissions

-perm/mode

-perm-mode

MODE: Indicates that nine permission bits must be strictly matched, such as-perm 644, then only files with permission rw-r--r--are eligible

/mode: Indicates that nine permission bits have one match, such as-perm/644, 644 means that the permission is rw-r--r--, so long as one of the same files is eligible, such as 004 permissions file

-mode: Indicates that the file permission must contain lookup standard permissions, such as-perm-644, 644 means that the permission is rw-r--r--, then the permissions matching the file must contain rw-r--r--, such as 644 permissions, 755 permissions

3. According to the owner of the document, belong to the group to find-user-group

-user Hadoop to find what files are owned by the main Hadoop

-group Hive Find what is the file of the group is hive

-uid,-gid based on the ID number of the main genus of the file

-nouser: Finding files that are not owned by the master

-nogroup: Finding files that are not owned by a group

When a user is deleted, the owner group of the previous file belonging to that user becomes the uid,gid of that user, and finding these files can be done using the above UID or Nouser method

4. Find-size "+|-" based on file size #

Units have k,m,g default is bytes, before the number + number means to find files larger than the specified size

-sign to find files that are smaller than the specified size

5. Search by file name

-name Case Sensitive

-iname Case insensitive

In addition, the file name can be used with wildcard characters

6, based on time stamp lookup

-ctime "+|-" #最近一次改变时间

-mtime Last Modified Time

-atime Last access time

#表示最近一次--Time is right now # days

-#表示 # files that have been accessed within the day (the last time the file is within the # days from now)

+ #表示 # files that were accessed before the day (the last time the file was--from now on # days ago)

-cmin-mmin-amin (unit is minutes, usage ibid.)

7. Using the combination condition test

-A: With

-O: Or

-not: Non-

Action:-ls (Displays the found file in ls-l format)

-print (default behavior)

-ok COMMAND

-exec commend

-ok and-exec can be used after the shell command, if the command needs to enter the command processing files, using {} Refer to the Find command to locate the file, the shell command after the entire statement must use \; End

The difference between-ok and-exec:-OK requires manual confirmation by the user before each operation, and-exec does not need

This article is from the "Zxcvbnm Xuan ye" blog, please be sure to keep this source http://10764546.blog.51cto.com/10754546/1701477

Linux file Find command application for find

Related Article

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.