File search,
1. Use [which/whatis/whereis]
Whereis Query file location whatis query command help whichis view Executable File Location
2. find command
Find path-option [-print] [-exec-OK command] {};
Parameter description:
Find judges the path and expression according to the following rules, and first-() in the Command column -(),! The previous part is path, followed by expression. If path is a Null String, use the current path. If expression is a Null String, use-print as the default expression.
There are more than 20 or 30 options available in expression. Here, we will only introduce the most commonly used options.
-Mount,-xdev: Only checks files in the same file system as the specified directory to avoid listing files in other file systems.
-Amin n: Read in the past n minutes
-Anewer file: The file that has been read later than the file.
-Atime n: Files Read in the past n days
-Cmin n: modified in the past n minutes
-Cnewer file: The file that is updated later than the file.
-Ctime n: searches for files based on the file creation time.
-Mtime B: searches for files based on the file change time.
-Empty: empty file-gid n or-group name: gid is n or group name is name
-Ipath p,-path p: The file whose path name is p-compliant. ipath ignores case sensitivity.
-Name,-iname name: name of the file that matches the name. Iname ignores case sensitivity.
-Size n: the file size is n units. B indicates the block of the 512-bit tuples. c indicates the number of characters, k indicates kilo bytes, and w indicates two-bit tuples. -
-Type c: the file type is c. Add above! Indicates that
-Perm: search by File Permission
-User |-nouser Owner | No uid
-Group |-nogroup group | no gid
-Exec: Execute the shell command given by this parameter on the matching file.
-OK: The Role of-exec is the same. A prompt is displayed before each command is executed, asking the user to determine whether to execute the command.
-Delete: delete an object.
-Ls: List objects
-Print: print
Parameter:-t indicates that the command is printed first and then executed
-I assigns each item name and one row {},
Instance: find common files that were modified seven days ago in the/var/logs directory and ask them before deletion:
$ Find/var/logs-type f-mtime + 7-OK rm {};
The owner of the files in the preceding directory has the read and write permissions, and the users in the file group and other users have the read permissions:
$ Find.-type f-perm 644-exec ls-l {};
To find all common files with a length of 0 in the system and list their full paths:
$ Find/-type f-size 0-exec ls-l {};
Find./-name 'file * '| xargs-ti mv {} ../{}. bak
Find/rootDesktop/test-name 'test. * '| xargs-ti mv {}{}. log
Find/etc/-name *. conf-exec cp {}/backup \;