3rd Linux Common Commands (3) _ File Search command

Source: Internet
Author: User

3. File Search command

3.1 File Search: Find

(1) Find command

Command name

Find

Command path

/bin/find

Execute permissions

All Users

Grammar

Find [Search Range] [-options] [match criteria]

-name: Search by file name

-iname: Search by file name, but ignoring case

-inum: Based on I-node lookup

-size [+-n]: Based on file size lookup,+n greater than,-n less than, n equals

where n is in: the size of the data block (512 bytes, or 0.5K)

-amin,cmin,mmin: Find based on time attributes (access, file attributes (such as permissions, owner, etc.)change, file content modify). Back +-time, units minutes, + represents greater than,-indicates less than.

-user,-group: Based on owner lookup, owning group lookup

-type: Search by text type, f file, D directory, l soft link file

-exec/-ok Command {} \; : This is a format that is fixed and is used primarily to perform operations on search results, where-ok asks for an action.

(2) Precautions

①find is a precise match, which is the exact matching condition of the search results.

② if you want to make a fuzzy match, you can add a match condition to match a single character.

③ matching criteria can be connected using-A and-O,-a for and connections,-O for or connections

(3) Application examples

① find file in directory/etc Init: #find/etc–name Init

② Search/etc/for all files with file names beginning with "Init":

#Find /etc–name *init-a–type F

③ look for files that are larger than 80MB and less than 100MB under the root directory:

#Find /-size +163840 –a–size-204800 (100mb=204800*0. 5KB)

④ Find files with owner TestUser under the root directory: #find/-user TestUser

⑤ Find files and directories with properties modified within 5 minutes under/etc: #find/etc–cmin-5

⑥ find the Inittab file under/etc and display its details:

#Findls -ld {} \;

3.2 find files in file repository: Locate

(1) Locate command

Command name

Locate

Command path

/usr/bin/locate

Execute permissions

All Users

Grammar

Locate [-options] [filename]

-I: Ignore case

(2) Precautions

① system for file Building database (/VAR/LIB/MLOCATE/MLOCATE.DB) and regular updates, and then directly in the library to find, so the search speed .

The ②locate installation package is named Mlocate (Yum list available | grep locate view), installation method:

Yum-y Install Mlocate, then execute updatedb;

③ the new file will not be paid to the database in time, so UpdateDB is executed. Also note that the files under/TMP cannot be paid to the database.

(3) Application examples:

① find files with file name Inittab in system: $locate Inittab

② find locate this file itself: $locate locate

3.3 Search Directory and alias information: which

(1) which command

Command name

which

Command path

/usr/bin/which

Execute permissions

All Users

Grammar

which command

(2) Application examples:

① to see if the RM command has an alias : #which RM

② Find the command and whether there are aliases in the directory: #which useradd

3.4 Search the directory where the command is located and the Help document path: Whereis

(1) Whereis command

Command name

Whereis

Command path

/usr/bin/whereis

Execute permissions

All Users

Grammar

Whereis [command name]

(2) Application examples:

① View ls command directory and help document path : #whereis ls

3.5 searches for a string-matched line in the file and outputs: grep

(1) grep command

Command name

grep (English literal:global Regular expression print)

Command path

/bin/grep

Execute permissions

All Users

Grammar

Grep–iv [Specify string] File

-I: Ignore case

-V: Excludes specified strings

(2) Application examples:

① View information about MySQL in the installation log: #grep Mysql/root/install.log

② View the contents of a file in addition to the Comment line :

#grep//^ Indicates the beginning of the line, #是注释的开始

3rd Linux Common Commands (3) _ File Search command

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.