File Lookup command under Linux--find

Source: Internet
Author: User

Several common file lookup commands under Linux:

Which viewing the location of an executable file
Whereis looking for a specific file, view the location of the file
Locate to view file locations with a database
Find actual search hard disk query file name

Usually the find command is not very common, and everyone is preferred to use the Whereis and locate commands to find, because Whereis and locate commands are using the database to find the location of the file, and do not actually query the hard disk, so fast, save time. But our find command is still very powerful, it looks for a lot of conditions, for other commands can not find files, you may consider using the Find command to traverse the hard disk lookup, although slow and inefficient.

Find (used to find files in the file tree and do the appropriate work)

Format: Find [PATH] [option] [action]

[PATH]: The directory to search for traversal, default to the current directory

[option]: Conditional characteristics of the file to search for

[Action]: Special handling of search results

    • To shorten the execution time of the instruction, try to minimize the starting directory of the search. Because the find instruction iterates through the directory recursively, the range of the starting directory is large, which causes the find command to run too long.
    • When no parameters are added, the current directory and its subdirectories are traversed by default, displaying them all on the screen.

1. Time-related parameters

-amin n : Find files that have been accessed in n minutes

-cmin n : Finds all files that have been modified in n minutes by file status

-mmin n : Find all files that have been modified in n minutes by the contents of the file

-atime n : Lists the files accessed in n days
-ctime n : Lists changes in n days, new files or directories
-mtime n : Lists the modified files or directories in n days
-newer file: List the files that are more new (can be used to identify the old and new relationships between the two files)

In addition, take-mtime as an example: (analogy uses other time-related parameters)

-mtime N: Lists files that were changed the day before n days

-mtime +n: Lists files that have been changed before N days (not including the N-day itself)

-mtime-n: Lists files that have been changed within n days (containing the N-day itself)

-mtime 0:0 represents the current time, which lists the changed files from now to 24 hours ago

2. Parameters related to user or user group name

-uid N : Looking for a file with owner ID n

-gid N : Looking for a file with user group ID n

-group name : Look for all files with the group name named name

-user name : Find all files with a name of the user

-nouser : Looking for someone who does not exist/etc/passwd (can find files that are not quite normal)

-nogroup : All user groups looking for files that do not exist in the/etc/group file

If you delete an account, the file created by the account becomes a non-master file, and you can use-nouser to find the type of file

3. Parameters related to file permissions and names

(1)-name [filename] : Find files with file name filename

From the example above, we can see that the Find command requires a pathname as the lookup scope, and find goes deep into each subdirectory of the path to find the absolute path of the printed file.

If you specify a path of "/", the entire file system is searched. The-name option specifies the file name,-printf indicates that the result is output to the screen, and the-type option is used to locate the special file type.

(2)-size [+-]size : Lookforfiles larger than "size" (+) or small (-) Size:①c: Represents the byte ②k: On behalf of the 1024x768 BYTES), use "-size +50k" to find files larger than 50k

(3)-type [type] : Find Files of type file

Common parameters for the-type option:

Parameters Meaning
B Block device files
C Character device files
D Catalog files
F Normal file
P Named pipes
L Symbolic Links

(4)-perm [mode] : Find file permissions just equal to "mode" of the file, this "mode" is similar to the Chmod property values

-perm [+mode] : Find file permissions All files that contain "mode" permission

-perm [-mode] : Find file Permissions file with any "mode" permission

4. Other

-exec [command] : command for other commands,-exec can be followed by other commands to handle the results found.

-exec to "\;" Is the keyword that represents the start-to-finish of the Find Extra command, which is the extra command for the Find command

-print : Prints the results to the screen, the default action

File Lookup command under Linux--find

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.