File Search command: locate Whereis which find
String Search Command grep
Locate
Usage: Locate file name
-Because the locate command searches in the background database by file name, it does not need to search the entire system file, all searches are faster.
-/var/lib/mlocate
Locate command Search background database, background database is not updated in real-time, the default is one day update. In some Linux systems, this background database name is not the same.
-updatedb
Update the database (you can search for new files after updating)
Cons : You can only search by file name.
advantages : Faster searches and less resources.
The locate default rule is to search according to/etc/updatedb.conf profile content, and Whereis which also searches by this rule.
-prune_bind_mounts = "Yes"
#开启搜索限制.
-prunefs =
#搜索时, do not search the file system.
-prunenames =
#搜索时, do not search for file types.
-prunepaths =
#搜索时, do not search for the path.
where and which
Command's Search command
Usage: whereis command name
#搜索命令所在路径及帮助文档所在位置
Options:
-B: Find only executable files
-M: View only Help files
Usage which command name
#搜索命令所在路径及别名
Find
Find [Search scope] [search criteria]
#搜索文件
Find/-name Install.log
#避免大范围搜索, system resources are very expensive
#find是在系统当中搜索符合条件的文件名. If a match is required, wildcard matches are used, and the wildcard character is an exact match
Wildcard characters in Linux
* Match any Content Find/-name "*". PHP
? Match any one of the characters Find/-name a "?". PHP
[] Match any one of the characters in brackets find/-name "AB[CD]"
- Find/-iname Install.log
#不区分大小写
- Find/-user root
#按照所有者搜索
- Find/-nouser
#查找没有所有者的文件
- Find/var/log-mtime +10
#查找10天前修改的文件
-10 files modified within 10 days
10 10 days of modified files on the same day
+10 files modified 10 days ago
Atime File access time
CTime changing file properties
Mtime Modifying file contents
- find-size +25k in M-byte search +25m
#按照文件大小搜索文件
- Find. Inum 262422
#查找i节点是262422的文件
- find/etc/-size +20k-a-size-50k
#查找/etc/directory, files larger than 20k and less than 50k
-a:and
-o:or
- find/etc/-size +20k-a-size-50k-exec ls-lh {} \;
#查找 files larger than 20k and less than 50k in the/etc/directory, and displays detailed information
#-exec/-ok Command {} \; Perform action on search results
Grep
grep [Options] string file name
#在文件中匹配符合条件的字符串
Options:
-I: Ignore case
-V: Take counter
-N: Displays matching lines and line numbers.
The difference between find and grep:
Find command: Searches the system for eligible file names, and if matching is required, wildcard matches are used, and wildcards are exact matches.
grep command: Searches the file for qualifying strings, matches with regular expressions if required, and regular expressions that contain matching
Linux Basic command "File Search command"