Linux Basic Tutorial Linux using the Find command to search for files common method records

Source: Internet
Author: User

Find Linux is a very powerful search command, through the man find to see the find manual , you can find the description of Find a screen, and estimated that it will take some time to read. Brother even Linux training

Small series summed up the next, sorting out the common use of find 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 thefind 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 first 0 days, that is today. This method is used to specify that it is useful to find files that have been modified for a certain day, for example , today is a lunar month, to find out the revised document, 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 0 two 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.



Linux Basic Tutorial Linux using the Find command to search for files common method records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.