Linux study notes -- find command (file search command)

Source: Internet
Author: User

Linux study notes -- find command (file search command)

Find is used to search for eligible files in the system.

The difference between the find command and the locate command:

Locate: 1) Non-real-time search; 2) indexes are dependent on indexes, which occupy resources. indexes are created automatically when the system is idle. You can use the updatedb command to update indexes; 3) fast search speed; 4) inaccurate search. Find: 1) Real-time search; 2) Precise search (whether or not there is a real-time search on the system); 3) Precise search (the search result is displayed only when the search conditions are absolutely met ); 4) The search speed is slow.

1. Command Format:

Find [search range] [Search Condition] [processing action]

2. Common Search Condition options:

-Name "file name": search by file name (wildcards can be used); wildcards include: * (matching any number of characters )? (Match any character) [] (match any character in the brackets) [^] (match any character not in the brackets)-iname "file name ": search by file name, and ignore case sensitivity (wildcards can be used);-user Username: search by owner;-nouser Username: Search for files without owner;-type file type: search by file type; file types: B (Block Device Files) c (character device files) d (directory files) f (common files) l (symbolic link files) s (socket file) p (Named Pipe file)-mtime unit attribute: search by the time when the file is modified (unit: "day"); for example: -mtime-10 (search for files modified within 10 days)-mtime 10 (search for files modified 10 days ago) -mtime + 10 (search for files modified 10 days ago)-atime unit attribute: search by file access time (in days);-ctime Unit Attribute: search by the time when the file property is changed (unit: "day");-mmin unit: search by the time when the file is modified (unit: "Minute "); -amin unit attribute: searches by file access time (unit: "Minute");-cmin unit attribute: searches by file attribute change time (unit: "Minute "); -size unit attribute: search by file size. For example,-size-10 k (search for files smaller than 10 k) -size 10 k (search for files with a size of 10 k)-size + 10 k (search for files with a size greater than 10 k) -size-25 M (search for files smaller than 25 M) (Note: "k" is lowercase, "M" is uppercase)-a: Combination conditions "and" (and) -o: combination condition "or" (or)-not |!: Combination condition "inverse"

3. Common handling actions:

"-Print" Default processing action; "-ls" serves as "ls-l"; "-exec command {}\;" executes the specified command on the searched file, the '{}' After the command indicates that the command references anything you find. "-OK command {}\;" this is an interactive "-exec ", you need to confirm each operation.

4. Common examples:

1) Find the file named "test1.py" under the/root/py directory.

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> 2) Find the file named "test1.py" in the/root/py directory (case-insensitive ).

3) Find the file ending with ". py" in the/root/py directory.

4) Find the file named "test1.py" or "test2.py" under the/root/py directory.

5) Search for the files whose names end with ". py" and whose owner is "root" in the/root/py directory.

6) Find the log files modified in the current log directory within "2 days.

7) Find and delete the modified log files in the current log directory.

8) Search for the files in the current log directory "greater than 25 KB" and display them in a user-friendly manner.

9) Search for the files "greater than 25 K and less than 50 K" in the current log directory and display them in a user-friendly manner.

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.