Find the files modified in the last 10 days of the system. Find.-mtime-10-execls-l {}\; delete can replace ls with rm with some common parameters and descriptions find/-amin-10 # find the file fi accessed in the system for the last 10 minutes
Find the files modified in the last 10 days of the system.
Find.-mtime-10-exec ls-l {}\;
You can replace ls with rm when deleting the ls.
Some common parameters and descriptions are provided.
Find/-amin-10 # search for files accessed in the last 10 minutes in the system
Find/-atime-2 # search for files accessed in the last 48 hours in the system
Find/-empty # search for files or folders that are empty in the system
Find/-group cat # find the groupcat file in the system
Find/-mmin-5 # search for the files modified in the last 5 minutes in the system
Find/-mtime-1 # search for files modified in the last 24 hours in the system
Find/-nouser # search for files belonging to the void user in the system
Find/-user fred # search for files belonging to the user FRED in the system
The following list is some of the conditions for searching the features of files that can be specified by the find command. No search conditions are listed here. you can find all the search functions of the find command in related Linux books.
-Amin n
Find the files accessed in the last N minutes of the system
-Atime n
Find the last n * 24 hours of files in the system
-Cmin n
Searches for the files in the last N minutes that have been changed.
-Ctime n
Searches for the last n * 24 hours of files in the system that have been changed.
-Empty
Search for blank files, empty file directories, or folders without subdirectories in the system.
-False
Find files that are always wrong in the system
-Fstype type
Search for files in the specified file system, for example, ext2.
-Gid n
Find the file whose ID is n in the system.
-Group gname
Find the files in the system that belong to the gnam file Group and specify the group and ID.
Description of the control options of the Find command:
The Find command also provides some special options for users to control the search operation. The following table lists the basic control options and usage of the most commonly used find command.
Option
Purpose description
-Daystart
. Test the system's files within 24 hours from today. usage is similar to-amin
-Depth
Using the depth-level search process, you can first find the file content in the specified directory at a layer.
-Follow
Follow the wildcard link query method. In addition, you can ignore the wildcard link query method.
-Help
Show command summary
-Maxdepth levels
Search for directories at a certain level by the descending method
-Mount
It is not found in the file system directory. the usage is similar to-xdev.
-Noleaf
Do not optimize searches in non-UNUX file systems, MS-DOS systems, CD-ROM file systems
-Version
Print version numbers
After the-follow option is used, the find command follows the wildcard link method for search. unless you specify this option, the find command will generally ignore the wildcard link method for file search.
-The purpose of the maxdepth option is to restrict the "find" command to search for files in a directory in descending mode, or to search for directories that exceed a certain level. This slows down the search speed, the search takes too much time. For example, to find a file named fred in the subdirectory of the current (.) directory tip, run the following command:
Find.-maxdepth 2-name fred
If the fred file is in the./sub1/fred Directory, the command will directly locate the file and it is easy to find the file. If the file is in the./sub1/sub2/fred Directory, this command cannot be found. Because the maximum query directory level of the find command in the directory is 2, you can only find files under the 2-layer directory. The purpose of this operation is to allow the find command to locate files more accurately. if you already know the level of the file directory where a file is located, then, the added-maxdepth n can be quickly searched in the specified directory.
Search for files using hybrid search
The find command can use a hybrid search method. for example, we want to find a file larger than 100000000 bytes in the/tmp directory and modify it within 48 hours, we can use-and to link two search options into a hybrid search method.
Find/tmp-size + 0000000c-and-mtime + 2
Anyone who has studied computer languages knows that in computer languages, they use and or to indicate the relationship between "and" and "or. Search commands in Linux are also common.
In addition,
Find/-user fred-or-user george
We can interpret it as finding files belonging to both fred and george in the/tmp directory.
You can also use the "non" link in the "find" command to find files. if you want to find all files that do not belong to panda in the/tmp Directory, use a simple
Find/tmp! -User panda
Command to solve the problem. Very simple.
How to find and display files
Finding a file is our purpose. we 'd like to know the details and attributes of the file. if we look for the file, it is quite tedious to use the LS command to view the file information. now we can use these two commands together.
Find/-name "httpd. conf"-ls
After finding the httpd. conf file, the system displays the httpd. conf file on the screen.
12063 34-rw-r -- 1 root 33545 Dec 30/etc/httpd/conf/httpd. conf
The following table lists common parameters and usage methods for searching and displaying file information.
Option
Purpose description
-Exec command;
Search for and execute commands
-Fprint file
Print the complete file name
-Fprint0 file
Print the complete file name, including empty files
-Fprintf file format
Print File format
-OK command;
Run commands for the user and confirm the input according to user Y.
-Printf format
Print File format
-Ls
Print files of the same file format.