Linux Common Command 002 Search command Locate, Whereis, which, find, grep
-20150811
Common Search Commands
-------File Search command----------
-->locate command-faster than find
Locate file name
Search by file name in the background database, search faster
/var/lib/mlocate
#locate命令所搜索的后台数据库
UpdateDB command
--The newly created file is not searchable with the locate command, and after updating the database you can
--You can manually update the database updatedb
Cons: Search by file name only
--------Command Search command----------
-->whereis command
Whereis command name
#搜索命令所在路径及帮助文档所在位置
Options:
-B----Find only executable files
-m----Find only help files
-->which file name
#搜索命令所在路径及别名
----------------Supplement-----------------------
PATH environment variable: Defines the paths of the system search command
[Email protected] ~]$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/jdk/bin:/bin:/usr/bin:/usr/x11r6/bin:/usr/local/bin
------------------------------------------
-------File Search command----------
-->find Command
Find [Search scope] [search criteria]
#搜索文件
--eg:find/-name install.log
#避免大范围搜索, it consumes system resources very much
#find是在系统当中搜索符合条件的文件名. If a match is required, wildcard matches are used, and wildcards are exact matches.
-------Add: Wildcard characters in Linux---------
*----Match any Content
? ----match any one character
[]----match any one of the characters in brackets
-----------------------------------------
--eg:find/root-iname Install.log
#不区分大小写
-eg:find/root-user Root
#按照所有者搜索
--eg:find/root-nouser
#查找没有所有者的文件
--eg:find/var/log/-mtime +10
#查找10天前修改的文件
-10----10 days to modify the file
Documents modified on the day of----10 days
+10----10 days ago Modified file
Atime----File access time
CTime----Changing file properties
Mtime----Modify the contents of a file
--eg:find.-size 25k
#查找文件大小是25kb的文件
# . Represents the current directory
-25k----files less than 25kb
25k----equal to 25kb files
+25k----files larger than 25kb
K, m----k lowercase, M uppercase
--eg:find.-inum 262422
#查找i节点是262422的文件
#ls-I--View I node
--eg:find/etc-size +20k-a-size-50k
#查找/etc/directory, files larger than 20kb and less than 50kb
-A and logic with, two conditions are met
-O or logic or, two conditions satisfy one can
--eg:find/etc-size +20k-a-size-50k-exec ls-lh {} \;
#把find命令查找出来的文件交给exec后的命令处理, {} \; must write
------- String Search command--------
-->grep Command
grep [Options] string file name
#在文件当中匹配符合条件的字符串
Options:
-I----ignoring case
-V----Exclude the specified string
the difference between the-->find command and the grep command
--find command: Search the system for eligible file names, if necessary match, wildcard match, wildcard is exactly match
--grep command: Search for eligible strings in a file, match with regular expressions if required, regular expressions contain matches
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux Common Command 002 Search command Locate, Whereis, which, find, grep