Five Linux file search commands: find, locate, whereis, which, type
Find: find the path of the file or directory
- Format: find [path] [expression]
- Expression:
- -Name: Find the file named filename
- -Perm: search by execution permission
- -Empty: searches for empty files or directories.
- -User: search by file owner
- -Group: search by group
- -Nogroup: Check for files without a valid group. That is, the file group does not exist in/etc/groups.
- -Nouser: Check for files with no valid owner, that is, the file owner is not stored in/etc/passwd.
- -Mtime: searches for files based on the file change time.
- -Atime: searches for files by file access time
- -Ctime: searches for files based on the file creation time.
- -Newer: query the files or directories updated at the change time.
- -Type: Check for block Device B, Directory d, character Device c, pipeline p, symbolic link l, common file f
- -Size n [c]: searches for files with the size of n blocks (512 bytes) [or n Bytes]
- -Inum: search by I Node
- -Depth: enable the local directory to be searched before entering the subdirectory.
- -Fstype: Query files in a certain type of file system. These file system types can be found in/etc/fstab.
- -Mount: The file query does not span the mount point of the file system.
- -Cpio: Use the cpio command to back up matching files to tape devices.
- -Prune: ignore a directory
- -Maxdepth: the depth of the queried directory
-
- -Exec: find the file and execute the following command find...-exec CMD {}\;
- -OK: ask if you want to execute the following command find...-OK CMD {}\;
-Perm mode indicates a strict match.-perm-mode indicates that 1 in the transition mode to binary must all match (no matter 0 bits) -perm + mode indicates that the value 1 required for switching mode to binary must be partially matched (no matter 0 bits)-ctime/atime/mtime/cmin/amin/mmin: searches by time in days: ctime, atime, and mtime are measured in minutes: cmin, amin, and mminc -- change indicate that the object property has been modified. a -- accessm -- modify indicates that the object content has been modified. + n indicates that the object content is changed before n days.-n indicates that the object content is less than n days.
- [Root @ rhel6 ~] # Find/etc/-name "host *" "Query files or directories starting with host in the/etc/directory (including subdirectories"
- [Root @ rhel6 ~] # Find-type l "Query files in the current directory whose file type is link"
- [Root @ rhel6 ~] # Find-size + 0000000c "querying files larger than 10 MB in the current directory"
- [Root @ rhel6 ~] # Find-size-1 K "querying <1 K files in the current directory"
- [Root @ rhel6 ~] # Find/etc-name inittab-o-size + 17 M "Query files with names inittab or files> 17M in the/etc/directory"
- [Root @ rhel6 ~] # Find/etc-name "*. conf" [-a]-size + 20 k "Query files whose names are *. conf and whose names are <20 k in the/etc/directory"
- [Root @ rhel6 ~] # Find/etc/*-name "*. conf"-not-name "* http *" Query files whose names are *. conf but do not contain http in the/etc directory"
- [Root @ rhel6 ~] # Find/etc/-empty "query empty files or empty directories in the/etc/directory"
- [Root @ rhel6 ~] # Find/var-user Oracle "query the files or directories in the/var/directory that belong to the user's oracle"
- [Root @ rhel6 ~] # Find/home-group xfcy
- [Root @ rhel6 ~] # Find-inum 1024 "query the files or directories with an I node of 1024 in the current directory"
- [Root @ rhel6 ~] # Find-newer new "query new files or directories in the current directory than new files"
- [Root @ rhel6 ~] # Find/etc/-nouser-o-nogroup "Query files or directories (dangerous files) that do not belong to local users in the/etc/directory )"
- [Root @ rhel6 ~] # Find/data/-mmin-10 "Query files whose content has been modified within 10 minutes in the/data/directory"
- [Root @ rhel6 ~] # Find/proc/-type f-maxdepth 1 "Query files of the common file type in the/data/directory without querying subdirectories"
-
- [Root @ rhel6 ~] # Find/data/-mtime-10-exec rm {}\; "query and delete the modified files in the/data/directory within 10 minutes"
- [Root @ rhel6 ~] # Find/data/-mtime-10-OK rm {}\; "query the files whose content has been modified within 10 minutes in the/data/directory and ask whether to delete the files (y/n )"