The usage is summarized as follows:
Find pathname-options [-print-Exec-OK]
Pathname: Search Path
-Option: The main options are as follows:
-Name: search by document name
-Perm: search by document permission
-Prune: the path is not currently specified. If the-depth option is specified, prune is ignored.
-User: search by document owner
-Group: search by document Group
-Mtime-N + N: query by document change time. -N indicates that the distance from the current time is less than N days; + N days away
-Nogroup: Search for Invalid Group documents
-Nouser: Search for invalid owner document
-Newer file1! File2: search for documents whose changes are earlier than file1 and earlier than file2
-Type: search for a type of document
B: block device documentation
D: Directory
C: character device documentation
P: MPS queue documentation
L: Symbolic Link document
F: Common Document
-Size N [c]: [c] indicates that the document length is measured in bytes.
-Depth: When searching, first find the current directory document, and then find it in its subdirectory
-Fstype: searches for documents in a certain type of document system. The document system type can be found in/etc/fstab.
-Mount: finding documents does not span the mount point of the Document System
-Follow: If you encounter a link document, you can trace the document to which the link points.
-Cpio: Use the cpio command to back up documents to tape devices.
-Print: outputs matching documents to standard output.
-Exec: Execute the given shell command on the matching document. Format: Command {}/; Note the space between {} And /;
-OK: It works the same as-exec. Run the shell command given by this parameter only in a safer mode. Before executing each command, a prompt is displayed, asking the user to determine whether to execute the command.
Common usage examples of find in Linux
· Find path-Option [-print] [-Exec-OK command] {}/;
#-Print: output the searched documents to the standard output
#-Exec command {}/; ----- execute the command operation on the retrieved document. 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 document named filename
-Perm # search by execution permission
-User Username # search by document owner
-Group groupname # search by group
-Mtime-N + N # search for a document based on the document change time.-N indicates that the document is less than N days, and + N indicates that the document is earlier than N days.
-Atime-N + N # query gin by document access time: 0px ">-Perm # query by execution permission
-User Username # search by document owner
-Group groupname # search by group
-Mtime-N + N # search for a document based on the document change time.-N indicates that the document is less than N days, and + N indicates that the document is earlier than N days.
-Atime-N + N # search for documents by document access time.-N refers to N days or less, and + N refers to N days before.
-Ctime-N + N # search for a document based on the document creation time.-N indicates that the document is less than N days, and + N indicates that the document is earlier than N days.
-Nogroup # query documents without a valid group, that is, the document group does not exist in/etc/groups.
-Nouser # query documents without a valid owner, that is, the owner of the document is not stored in/etc/passwd.
-Newer F1! F2 documentation,-N refers to less than N days, + N refers to N days ago
-Ctime-N + N # search for a document based on the document creation time.-N indicates that the document is less than N days, and + N indicates that the document is earlier than N days.
-Nogroup # query documents without a valid group, that is, the document group does not exist in/etc/groups.
-Nouser # query documents without a valid owner, that is, the owner of the document is not stored in/etc/passwd.
-Newer F1! F2 # query documents whose changes are 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 documents.
-Size N [c] # query documents with a length of N [or n Bytes]
-Depth # search for the local directory before entering the subdirectory
-Fstype # query documents whose change time is newer than F1 but earlier than F2
-Type B/D/C/P/L/F # Check Block devices, directories, character devices, pipelines, symbolic links, and common documents.
-Size N [c] # query documents with a length of N [or n Bytes]
-Depth # search for the local directory before entering the subdirectory
-Fstype # query documents in a certain type of document system, which can be found in/etc/fstab.
-Mount # the document does not span the mount point of the document system.
-Follow # If you encounter a symbolic link document, you can trace the document referred to by the link.
-Cpio %; # query documents in a certain type of document system, which can be found in/etc/fstab.
-Mount # the document does not span the mount point of the document system.
-Follow # If you encounter a symbolic link document, you can trace the document referred to by the link.
-Cpio # Use the cpio command for matching documents to back up them to tape devices.
-Prune # ignore a directory
========================================================== ================
$ Find ~ -Name "*. txt"-print example: Check the. txt file in home‑based and display the file.
$ Find.-Name "*. txt"-print
$ Find.-Name "[A-Z] *"-pri26nbsp; # Use the cpio command for matching documents to back them up to tape Devices
-Prune # ignore a directory
========================================================== ==================
$ Find ~ -Name "*. txt"-print example: Check the. txt file in home‑based and display the file.
$ Find.-Name "*. txt"-print
$ Find.-Name "[A-Z] *"-print # query documents starting with an uppercase letter
$ Find/etc-name "Host *"-print # query documents starting with host
$ Find.-Name "commana-z00000000a-z0000000000000--9000000000--90000.txt"-print # query TXT documents starting with two lower-case letters and two numbers
$ Find.-Perm 755-print
$ Find.-Perm-007-exec LS-l {}/; # query the documents that can be read and written by any user, which is the same as-Perm 777
$ Find.-type D-print
$ Find .! -Type D-print
$ Find.-type L-print
$ Find.-size + 000000c-print # query documents with a length greater than 1 MB
$ Find.-size 100c-print # query documents with a length of 100c
$ Find.-size + 10-print # query documents with a length of over 10 expired items (1 piece = 512 bytes)
$ CD/
$ Find etc home apps-depth-print | cpio-ivcsc65536-o/dev/rmt0
$ Find/etc-name "passwd *"-exec grep "cnscn" {}/; # check whether a cnscn user exists
$ Find.-Name "Yao *" | xargs File
$ Find.-Name "Yao *" | xargs echo "">/tmp/CORE. Log
$ Find.-Name "Yao *" | xargs chmod o-w
========================================================== ====================
Find-name CMDL * search for documents starting with CMDL in the current directory
Find-name CMDL * fprint file: Search for the document starting with CMDL in the current directory, and output the result to file.
Find-name AP *-o-name may * search for documents starting with AP or may
Find/mnt-name tom.txt-FTYPE vfat under/mntsearch for documents named tom.txt and whose system type is vfat
Find/mnt-name t.txt! -FTYPE vfat: Find a file named tom.txt under/mntand the file system type is not vfat.
Find/tmp-name wa *-type l search for documents starting with Wa and whose type is symbolic link under/tmp
Find/home-mtime-2 check the document changed in the last two days under/home
Find/home-atime-1 check the documents that have been accessed within one day
Find/home-mmin + 60 check the document changed 60 minutes ago under/home
Find/home-Amin + 30 query documents that have been accessed in the last 30 minutes
Find/home-newer tmp.txt check the documents or directories that are updated at a time closer to tmp.txt under/home.
Find/home-anewer tmp.txt check the documents or directories that are stored for a time closer than tmp.txt in/home.
Find/home-used-2 list the files or directories that have been accessed within two days after the files or directories have been changed.
Find/home-user cnscn list the documents or directories belonging to the user cnscn in the/Home Directory
Find/home-UID + 501 list documents or directories with user IDs greater than 501 in the/Home Directory
Find/home-group cnscn list/home documents or directories with cnscn groups
Find/home-gid 501 list documents or directories with group IDs 501 in/home
Find/home-nouser: List documents or directories that do not belong to local users in/home.
Find/home-nogroup list documents or directories in/home that do not belong to the Local Group
Find/home-name tmp.txt-maxdepth 4 list/The tmp.txt in homecan be found at a maximum of three layers.
Find/home-name tmp.txt-mindepth 3 query from Layer 1
Find/home-empty
Find/home-size + 512 K query documents larger than K
Find/home-size-512 K query documents smaller than K
Find/home-links + 2 query documents or directories with hard connections greater than 2
Find/home-Perm 0700 check documents or directories with the permission of 700
Find/tmp-name tmp.txt-exec cat {}/;
Find/tmp-name tmp.txt-OK RM {}/;
Find/-Amin-10 # search for documents accessed in the last 10 minutes of the system
Find/-atime-2 # search for documents accessed in the last 48 hours in the system
Find/-empty # search for documents or folders that are empty in the system
Find/-group cat # search for documents that belong to groupcat IN THE SYSTEM
Find/-mmin-5 # search for documents modified in the last 5 minutes of the system
Find/-mtime-1 # search for documents modified in the last 24 hours in the system
Find/-nouser # search for documents that belong to the void user in the system
Find/-user Fred # search for documents belonging to the user Fred IN THE SYSTEM
Query any common documents in the current directory
--------------------------------------------------------------------------------
# Find.-Type F-exec LS-l {}/;
-RW-r -- 1 Root 34928 2003-02-25./CONF/httpd. conf
-RW-r -- 1 Root 12959 2003-02-25./CONF/magic
-RW-r -- 1 Root 180 2003-02-25./CONF. d/readme
Query any common documents in the current directory and use the LS-l command in the-e x e c option to list them.
========================================================== ==========
In the/l o g s directory, find the files whose changes were earlier than 5 days and delete them:
$ Find logs-type F-mtime + 5-Exec-OK RM {}/;
========================================================== ==========
Query the modified documents on the current day
[Root @ book class] # Find./-mtime-1-type F-exec LS-l {}/;
========================================================== ==========
Query the document and ask if you want to display it
[Root @ book class] # Find./-mtime-1-type F-OK ls-l {}/;
? Y
-RW-r -- 1 cnscn 13709 January 12 12:22./classdb. Inc. php
[Root @ book class] # Find./-mtime-1-type F-OK ls-l {}/;
? N
[Root @ book class] #
========================================================== ==========
Query and submit it to awk for processing
[Root @ book class] # Who | awk '{print $1 usd/t "$2 }'
Cnscn pts/0
========================================================== ==========
Awk --- grep --- SED
[Root @ book class] # DF-k | awk '{print $1}' | grep-V 'none' | sed s "// Dev // G"
Document System
Sda2
Sda1
[Root @ book class] # DF-k | awk '{print $1}' | grep-V 'none'
Document System
/Dev/sda2
/Dev/sda1
1) Search for any *. h In/tmp, search for "syscall_vector" in these documents, and print out any document 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 documents 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 you have a special document that can use cpio, you can also use this syntax:
Find Dir-name filename-print | cpio-PDV newdir
6) Find the modified document at 16:36:37,-11-30.
# A = 'Find./-name "* PHP" '| LS-l -- full-time $ A 2>/dev/null | grep "2004-11-30 16:36:37"