Basic Linux Training tutorial using
Find is a very powerful search command for Linux, and with man find, you can find the description of Find in one screen, and it will take some time to read it. Brother even the Linux training to summarize the next, sorting out the use of find common methods.
1. Command format
Find search Path Search expression
Search path: This is relatively easy to understand, is the specified search directory, such as/etc. Search path can also specify multiple, separated by a space can be, such as/etc/home.
Search expression: The key to the Find command is that on an expression, there are many options for an expression. The following command tests are primarily divided by the options of the expression.
2. Command test
A. Search for files by file name
This feature is quite common, as shown in the following example:
$ Find/etc-name ' apache2 '
/etc/default/apache2
/etc/php5/apache2
/etc/apache2
/etc/logrotate.d/apache2
/etc/cron.daily/apache2
/etc/init.d/apache2
This-name option is more commonly used, followed by a file name to search. The above example is used to search for files in the ETC directory where the file name is apache2. Another thing to note is that this is an exact search, and only the file name is apache2 to be searched. If you need a fuzzy search, you can use regular expressions, as in the following example:
$ Find/etc-name ' apache* '
B, search according to the file time
Sometimes want to find the most recently modified files, you can use the time option, time options have three kinds of atime, Mtime, CTime, the following mtime to explain.
Mtime N: Find the file that was changed in the previous Nth day
Mtime +n: Find the files modified N days ago, excluding the nth day, the mathematical interval is (-∞,-N)
Mtime-n: Find the changed files in n days, not including the Nth day, the mathematical interval is the expression (-n,0]
One of the-∞ said that a long time ago, 0 said today. It is obvious that the axes are used.
Linux Find command time option test
Find the files that have changed today
$ find/home Mtime 0
This way 0 means the No. 0 day, that is today. This method is useful for specifying a file that has been modified for a certain day, for example today is December 30, to find out which files were modified on 28th and to change 0 to 2. As follows:
$ find/home Mtime 2
Find files that have changed within 2 days
$ find/home mtime-2
The interval is expressed as ( -2,0], apparently only-1 and 2 numbers, respectively, representing yesterday and today.
Find files that were changed 2 days ago
$ find/home Mtime +2
C. find files by user or user group
This type of option is relatively common. Commonly used are:
-uid N: Search for files with user number n
-gid N: Search for files with user group number n
-user Name: Search for a file that belongs to the user named name
-group Name: Search for a file of the owning user group named name
Search for files that belong to the user named root
$ find/-user ' root '
Summarize
There are many options for the Find command, and you can refer to the Man Manual for additional options. Compared with the locate, find will actually scan the disk, relatively slower, small proposal can be done with locate locate fix.
Basic Linux Training tutorial using