Linux Common Commands (second Edition)--File Search command

Source: Internet
Author: User

File Search Command

1,which/usr/bin/which# display system command directory , Absolute Directory, can not find files

Format: which [ system command ]

E.g.which ls

Attached-whereis: can also find the absolute path of the command

Unlike Whereis , which lists the alias record for this command , and whereis displays the location of the Help document for the command.


2,find/usr/bin/find# file or directory, any file can, tablets, compressed package, etc.

Syntax:find [ search Path ] [ search Options ] filename

A)find/etc-name file name #-name most common options

Find/etc-name init// Find the file init file in the directory / etc

Attention:

As far as possible to narrow the scope of the search, do not look in the root directory, otherwise: 1, the search is very slow, 2, occupy a large number of system resources .

2- consume less system resources better , and try to find with find when the server is under a low pressure .

3-find. -name search results are different from Windows , such as: Windows will list all The files that contain the INIT keyword and Linux it will only match Init Key Words

4- Use a wildcard character :

*: Used to match any character

Find/etc-name init* #查找所有以 files that begin with Init

Find/etc-name *init* #init There are no spaces around to find all files that contain the init keyword

?: Used to match a single character

Find/etc-name Init??? #这个文件会有七个字符.

Find/etc-name init??

b)find/etc-size File Size

#他是以数据块为单位的! + byte = 0.5KB, 1K = 2Blocks

100m=? Blocks

100M = 102400K = 102400*2blocks

e.g

Find/etc-size +204800 #在/ etc to find files larger than 80MB greater than 100MB

find/etc-size-204800# in /etc to find files larger than 80MB less than 100MB

Find/etc-size 204800# in/ etc look for files equal to 100MB , not used!

C)find/etc-user username find files belonging to username

Find/home/xiaofang/programme/data_structure/-user Xiaofang


D) Find by Time value:

1. In days:ctime,atime,mtime

2, in minutes:cmin,Amin,mmin#更为常用

C-change change: indicates that the properties of the file have been modified , such as: Owner, owning group, permission

A-access Access: File has been browsed

M-modify Modification: The contents of the file have been modified

-How long,+ how much time

e.g.

Find/etc-mtime-1

Find/etc-amin-60

find/home-cmin-120

e)find/etc-type file Type # find by file type

F Binary Files

L Soft Link File

Catalog D

e.g.

Find/etc-type F

Find/etc-type L

F)-inum# Search based on I node

e.g.

Touch---abc# Delete : RM---ABC

Touch "A B" # delete : RM "a B"

Find. -inum 159341

Find. -inum 159341-exec rm-f {} \; #找到i - node 159341 file, and delete it

Attached-find connector:

1,-a: and Logic and

-O: or logical OR

e.g.

Find/etc-size +163840-a-size 204800# find >80m,<100m files

Find/etc-name init*-a-type F # finds files named init and is binary and does not contain directories

2.find ...-exec command {} \; #固定格式, that's the only way to write.

{}:find Query results

\: escape character -makes the symbolic command use its own meaning

;: Statement End

e.g.

Find/etc-name inittab-exec ls-l {} \;

Find the inittab file under #在/ etc and display its details

Find/home-user sax-exec rm-rf {} \;

#删除用户 all of sax files

Find/home-user sax-ok rm-rf {} \;#-ok connector

#删除用户sax All the files , he will prompt you whether to confirm

Find/etc-name init*-ok rm-rf {} \;

3. locate[list file in Databases]:/usr/bin/locate

Description

#是Linux -specific commands to find files or directories, preferably for quick location system Commands , configuration files , etc.

# Although the search is fast, but sometimes it can't be found

#locate is found in the file database, so the speed will be fast

# But if the database does not contain this file, he will not find it;

Format: Locate [ search keywords ]

Mates: updatedb [Update a database for Mlocate]:/usr/bin/updatedb

#建立整个系统目录文件的数据库

Note: Its execution permissions are:root!!!

4.grep:/bin/grep# searches the file for string matching lines and outputs

Format: grep [ Specify String ] [ source file ]

E.g.grep ftp/etc/services

Attached:grep is particularly powerful, supports regular expressions, and her more specific introduction please refer to my other blog post:

Four days proficient in shell programming ( two )

Linux Common Commands (second Edition)--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.