Find command detailed under Linux __linux

Source: Internet
Author: User
Tags file permissions

This blog is about Linux file Lookup command: Locate and find, where locate is very simple, mainly explain the finding command locate

Usage

Locate To/find/file/name

Just add the file name you want, but the locate may not be accurate, or you may not find what you need.
Because locate is actually looking for a file database, it's very fast, but it's a precise match, and if the file you just created wants to find it, because the database is still not updated, you can't find

Update file Database

UpdateDB

The speed is very slow, depending on how much of the file in your system find

Due to the locate and non-real-time lookup characteristics, locate is not used much
Find supports real-time lookup, with many search options, is the most commonly used on Linux, but the disadvantage is more obvious: If the number of documents, the search is very slow

Whatever,find is still the most useful and commonly used Linux Lookup command usage

Find support for file name of the regular expression lookup, according to file modification time to find, by file size lookup, file permissions, search by file type, find out later also support directly to find the file to use commands, the function is very powerful

The typical find command is written as:

Find the criteria for finding a path lookup to the action after

For example: find/home-type d-ls
Find out all the directories under/home/and display the details of the table of contents options by file name -name
Add file name directly, and support filename wildcard Iname
Similar to-name, but not case-sensitive when matching file names-regex
Regular expression matching filename

Example

Find. -name "vim*"-ls
Finds all files that begin with vim in the current directory and displays their details
Find. -iname "vim*"-ls
Finds all files that start with Vim in the current directory (case-insensitive) and displays their details find-type by file type D: directory F: normal file L: Link file (link) s:socket file p: Piping file (pipe) B: block Device file C: Character device file

Example

Find. -type D-ls
Displays the details of all the directories under the current directory
Find. -type L-ls
Displays the details of all the linked files under the current directory/owner find-gid gid-uid uid-user user-group group-nouser-nogroup by file-owning group

Exmaple:

Find. -user Gavinzhou-ls
Displays details of all files belonging to Gavinzhou under the current directory find size by file size [+,-][b,k,m,g]

Example

Find. -type f-size +1k-ls
Displays details of all normal files larger than 1k in the current directory find CTime by file modification time : Change time (calculated by day) Atime: Access time Mtime: Modify Time
-amin: Change time (calculated in minutes)
-cmin: Access Time
-mmin: Modification Time

Use [+,-] to represent [greater than, less than]

Example

Find. -atime-1-ls
Displays details of all files accessed within two days of the current directory
Find. -cmin +10-ls
Show details of all files in the current directory that have not changed over 10min Find by file permissions

-perm MODE
/mode: Any one match that satisfies the condition
-mode: File permissions can fully contain this MODE to qualify

Example

Find. -perm-644-ls
Displays the details of each of the files that contain at least r-xr–r– file permissions in the current directory
Find. -perm/464-ls
Displays the details of a file that contains at least r–rx-r– files under the current directory combination lookup

-a:and
-o:or
-not:

Example

Find. -type D-o-type L-ls
Displays details of all directories and linked files in the current directory subsequent command -print: Display-ls: Displays the detailed-quit of each file in a form similar to ls-l: Find one and exit-delete: Delete matching rows-ok command {} \; Each operation requires user confirmation, {} refers to the file found by reference, is placeholder-exec COMMAND {} \; No confirmation for each operation

Example

Find. -type D-delete
Deletes all directories under the current directory
Find. -type f-ok wc-l {} \;
Find all normal files in the current directory and display the number of rows (to confirm)
Find. -type f-exec wc-l {} \;
Find all normal files in the current directory and display the number of rows (no confirmation required)

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.