Linux commands: Find, locate

Source: Internet
Author: User

Quick Search: Locate

This command requires a pre-established database, the database is updated daily by default, and the database can be updated with the UpdateDB command. If you do not install locate with the Yum install–y mlocate installation, update the database with the UpdateDB command after installation (the result of this command is very inaccurate, we use the Find command in practice)

123. txt     // For example, we create a file 123. txt    // and then search for this file is not searchable [[ Email protected] ~~]# updatedb          // Update the database before you can find 123.txt/ root/123. txt

Advanced Search: Find

Usage: Find + file path + Find parameters

1. Name-based search

[[email protected] ~]# Find/-name passwd    // search for passwd files under the root directory /usr/bin/passwd/selinux/ class/passwd/selinux/class/passwd/perms/passwd/etc/passwd/etc/ pam.d/passwd

2. Type-based search

[[email protected] home]# find./-type D    // Search the directory under the current directory .///    D represents a search based on a directory type . /A[[email protected] home]# find. /-type F    // search for files in the current directory ./1. py    //F represents a search based on file type ./2 . py

3. Search based on time of change

-atime Last access time (in days)
-mtime Last content modification time (in days)
-ctime Last Property modification time (in days)
-amin Last access time (in minutes)
-mmin Last content modification time (in minutes)
-cmin Last Property modification time (in minutes)

[[email protected] home]# find./-mtime-5    //-5 for files that have changed within 5 days .     // If it is +5, it represents a file that has been modified for more than 5 days ./1. py. /A
[[email protected] home]# find./-mmin +5    //+5 for files that have been modified for longer than 5 minutes . /1. py. /A

Note: When we change the contents of the file, CTime also changes as the content of the file changes, which means that the file size is changed, which means that the property is modified, so ctime changes

[Email protected] home]# stat1. py//The stat command can view the file's Atime, Mtime, CTimeFile:"1.py"Size: theBlocks:8IO Block:4096Common file device:fd00h/64768d Inode:781923Links:1Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Access: .- ,- -  One: $:00.355757826+0800    //atime InformationModify: .- ,- -  One: $:58.826754450+0800    //mtime InformationChange: .- ,- -  One: $:58.870752238+0800    //CTime Information

4. File permission-based search

File permission-based search to add the –perm parameter

777    // search for files with file permissions of 777 in the current directory ./C. /B. /A[[email protected] home]# find. 644    // search for files with file permissions of 644 in the current directory ./1. py

Linux commands: Find, locate

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.