The Linux Find command searches the directory structure for files and performs the specified actions. The Linux Find command provides quite a lot of search criteria and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at. Even if the system contains a network file system (NFS), the Find command works equally well in the file system, and you only have the appropriate permissions. When running a very resource-intensive find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system with more than 30G bytes). 1. Command format:Findpathname-options [-print-exec-OK ...]2. Command function: Used to locate files in the file tree and to make corresponding processing3. Command arguments: The directory path that the Pathname:find command looks for. For example, use. To represent the current directory,/to represent the system root directory. -The print:find command outputs the matched file to standard output. The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form'Command'{} \;, note the space between {} and \; -ok: And-exec performs the same function, but executes the shell command given by the parameter in a more secure mode, prompting the user to determine whether to execute before executing each command. 4. Command options:-name finds files by file name. -Perm to find files according to file permissions. -prune Use this option to have the Find command not be found in the currently specified directory, and if the-depth option is used at the same time, then-Prune will be ignored by the Find command. -user finds the file according to the owner of the file. -Group finds files according to the groups to which the files belong. -mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, +n indicates that the file change time is now N days ago. The Find command also has-atime and-ctime options, but they all and-m time option. -nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs in/etc/does not exist in groups. -nouser find a file without a valid owner, that is, the owner of the file in/etc/does not exist in passwd. -newer file1!file2 Look for a file that changes time than the file File1 new but older than the file file2. -Type to find a file of a certain type, such as: B-block device files. D-directory. C-character device files. P-pipeline files. L-Symbolic link file. F-normal file. -size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes. -Depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories. -fstype: Find files located in a type of file system that are typically available in the configuration file/etc/fstab, this configuration file contains information about the file system in the system. -Mount: Do not cross the file system mount point when locating files. -follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to. -Cpio: Use the cpio command for matching files to back up these files to the tape device. In addition, the following three differences:-Amin N Find the last n minutes of files accessed in the system-atime N Find the last n in the system24-hour access to files-cmin n Find files in the last n minutes of the system changed file status-ctime N Find the last n in the system24-hour file with file status changed-mmin n Find files that have changed file data in the last N minutes of the system-mtime N Find the last n in the system24-hour file changed file data5. Use instance: Instance 1: Find the modified file command in the specified time:Find-atime-2output: [[email protected]~]#Find-atime-2../logs/Monitor./. bashrc./. Bash_profile./. Bash_history Description: Ultra-search for 48 hours of modified files instance 2: According to the keyword search command:Find. -name"*.log"output: [[email protected] test]#Find. -name"*.log" ./Log_link.log./Log2014.log./test4/log3-2. Log./test4/log3-3. Log./test4/log3-1. Log./Log2013.log./Log2012.log./Log.log./test5/log5-2. Log./test5/log5-3. Log./test5/Log.log./test5/log5-1. Log./test5/test3/log3-2. Log./test5/test3/log3-3. Log./test5/test3/log3-1. Log./test3/log3-2. Log./test3/log3-3. Log./test3/log3-1. Log description: Finds files that end with. Log in the current directory. ". "represents the current directory instance 3: Locate the file command according to the permissions of the directory or file:Find/opt/soft/test/-perm777output: [[email protected] test]#Find/opt/soft/test/-perm777/opt/soft/test/Log_link.log/opt/soft/test/test4/opt/soft/test/test5/test3/opt/soft/test/test3 Description: Find/opt/soft/test/file Instance 4 with permission 777 under directory: Find command by Type:Find. -type F-name"*.log"output: [[email protected] test]#Find. -type F-name"*.log"./Log2014.log./test4/log3-2. Log./test4/log3-3. Log./test4/log3-1. Log./Log2013.log./Log2012.log./Log.log./test5/log5-2. Log./test5/log5-3. Log./test5/Log.log./test5/log5-1. Log./test5/test3/log3-2. Log./test5/test3/log3-3. Log./test5/test3/log3-1. Log./test3/log3-2. Log./test3/log3-3. Log./test3/log3-1. Log[[email protected] test] #说明: Find common file instances that end with. Log in Directory 5: Find all current directories and sort commands:Find. -type D |Sortoutput: [[email protected] test]#Find. -type D |Sort../SCF./scf/bin./scf/Doc./scf/lib./scf/service./scf/service/Deploy./scf/service/deploy/Info./scf/service/deploy/product./test3./test4./Test5./test5/Test3[[email protected] test] #实例6: Find file by size command:Find. -size +1000c-print output: [[email protected] test]#Find. -size +1000c-Print:/test4./SCF./scf/lib./scf/service./scf/service/Deploy./scf/service/deploy/product./scf/service/deploy/Info./scf/Doc./scf/bin./Log2012.log./Test5./test5/test3./Test3[[email protected] test] #说明: Find files larger than 1K in the current directory
Linux Command Learning Note: Find command overview