Detailed description of the find command in Linux

Source: Internet
Author: User
In Linux, the find command details the find command in Linux searches for files in the directory structure and executes the specified operation. In Linux, the find command provides many search conditions and has powerful functions.

Common usage examples of find in Linux ·

find    path    -option    [    -print ]    [ -exec    -ok    command ]    {} /;

#-Print: output the searched files to the standard output
#-Exec command {}/; ----- execute the command operation on the retrieved file. There is a space between {} And /;
#-OK is the same as-exec, but you need to consult the user before the operation

-Name filename # search for a file named filename
-Perm # search by execution permission
-User Username # search by file owner
-Group groupname # search by group
-Mtime-N + N # Find the file based on the file change time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Atime-N + N # query gin by file access time: 0px ">-Perm # query by execution permission
-User Username # search by file owner
-Group groupname # search by group
-Mtime-N + N # Find the file based on the file change time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Atime-N + N # search for files based on the file access time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Ctime-N + N # Find the file based on the file creation time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Nogroup # Check for files with no valid group, that is, the file group does not exist in/etc/groups.
-Nouser # Check files with no valid owner, that is, the file owner is not stored in/etc/passwd.
-Newer F1! F2 file search,-N refers to N days or less, + N refers to N days ago
-Ctime-N + N # Find the file based on the file creation time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Nogroup # Check for files with no valid group, that is, the file group does not exist in/etc/groups.
-Nouser # Check files with no valid owner, that is, the file owner is not stored in/etc/passwd.
-Newer F1! F2 # Query files whose modification time is earlier than F1 but earlier than F2
-Type B/D/C/P/L/F # Check Block devices, directories, character devices, pipelines, symbolic links, and common files.
-Size N [c] # query objects with a length of N [or n Bytes]
-Depth # search for the local directory before entering the subdirectory
-Fstype # Query files whose change time is newer than F1 but earlier than F2
-Mount # The mount point of the file system is not crossed during file query.
-Follow # If a symbolic link file is encountered, the file indicated by the link will be tracked.
-Cpio # Use the cpio command to back up the matching files to the tape device.
-Prune # ignore a directory

For more information, refer to "Detailed description of the find command in Linux.

1) Search for all *. h In/tmp, search for "syscall_vector" in these files, and print out all file names containing "syscall_vector ".
A) Find/tmp-name "*. H" | xargs-n50 grep syscall_vector
B) grep syscall_vector/tmp/*. H | cut-d': '-F1 | uniq> filename
C) Find/tmp-name "*. H"-exec grep "syscall_vector" {}/;-print

2) Find/-name filename-exec Rm-RF {}/;
Find/-name filename-OK Rm-RF {}/;

3) For example, to search for files larger than 3 m on a disk:
Find.-size + 3000 K-exec LS-LD {};

4) copy the find to another place.
Find *. C-exec CP '{}'/tmp ';'
If a special file exists, you can use cpio or the following syntax:
Find Dir-name filename-print | cpio-PDV newdir

6) Search for the files changed at 16:36:37,-11-30.
# A = 'Find./-name "* PHP" '| LS-l -- full-time $ A 2>/dev/null | grep "16:36:37
Ii. usage of the find command in Linux 1. Basic usage:
Find/-name file name
Find ver1.d ver2.d-name '*. c'-print find the ver1.d and ver2.d *. c files and print them.
Find.-type D-print find from the current directory, only find the directory, and print the path name. It can be used to print the directory structure.
2. No error search:
Find/-name access_log 2>/dev/null
3. Search by size:
Find/-size 1500c (search for 1,500-byte files; c Indicates bytes)
Find/-size + 1500c (find files larger than 1,500 bytes, + indicates files larger)
Find/-size + 1500c (find files smaller than 1,500 bytes,-Indicates smaller)
4. By Time:
Find/-Amin n last n minutes
Find/-atime n last n days
Find/-Cmin n last n minutes change status
Find/-ctime n changes the status in the last n days
5. Others:
Find/-empty blank file, blank folder, folder without subdirectories
Find/-false find files that are always wrong in the system
Find/-fstype type: Find the file that exists in the specified file system. For example, if the type is ext2
Find/-gid N group ID n files
Find/-group gname group file named gname
Find/-depth n preferentially searches for file content in a specified directory at a Layer
Find/-maxdepth levels search in a hierarchical directory in descending Mode
6. Logic
-And and-or conditions or
7. Search for strings
Find.-Name '*. html'-exec grep 'mailto :'{}

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.