Shell Learning Locate and find commands

Source: Internet
Author: User

There are several commands on the Linux system for file search, such as: Locate,wheris and find are more commonly used in work.

1.locate command: Locate the lookup file is based on the/var/lib/mlocate database, which contains all the local file information, the Linux system automatically creates the database and updates it automatically every day. You have just created a file locally, but using the locate command to search for a local file, you need to update the local database manually using Updaetedb.

  Common use methods and parameters: The Locate file name #会匹配出本地 All files in the/var/lib/mlocate database that contain the name of the file that has been indexed.                                                                                                               [[email protected] ~]# locate/etc/passwd/etc/passwd/etc/passwd-[[email protected] ~]# Common Parameters-H--help                                                                                                          #显示帮助-V--version          #显示版本信息-B,--basename Match only the base name of path names #只匹配路径名的基本名称-C,--count only print Numbe R of found entries #只打印找到的条目数量-e,--existing only print entries for currently E              xisting files #仅打印当前存在的文件的条目-I,--ignore-case ignore case distinctions when matching patterns #忽略大小写-W,--wholename match whole path name #匹配整个路径名称 (default) 
     

The

2.find command: The Find command can search for any file in a non-accessible location according to different criteria, and supports multiple ways to process search results. Its workflow: (1) Search for all user-specified paths, including all subdirectories. (2) For each file encountered, all eligible files form a list, depending on whether they meet the user-specified criteria. (3) for the file of the result list, perform the user-specified action.

Parameters:-name filename #表示包含指定匹配模式的文件名-iname filename #表示包含指定匹配模式的文件名, case-insensitive-type #指定文件类型, F for normal files, D for directories, c for block devices, p for pipes, L indicates connection-user userid #匹配其所有者为指定用户ID的文件-group groupid #匹配其所有者的组为指定组ID的文件-size size #匹配其大小为size的文件-empety #匹配空文件-amin[-+]n #文件最后一次访问时间,-n means that the time is less than n minutes, +n means n minutes ago, n means just n minutes-atime [-+]n #天-cmin[-+]n #文件最后一次状态改变时间-ctime[-+]n #-mmin [-+]n #最后一次被 Modified Time-mtime [-+]n action:-print #默认动作, writing search results to standard output-fprint file #将搜索结果写入到file中-ls #以详细格式展示搜索结果-fls File # Writes verbose format results to file-delete #将结果文件删除-exec command {} \; #查找并执行命令, {} indicates the name of the search to-ok command {}\; #查找并执行命令, but the user is required to confirm the section, find a file containing a number 3 minutes ago and delete it. [[email protected] home]# ll-rsttotal drwxr-xr-x. 2 root root 4096 Mar 19:34 ISO4 drwx------.   4 xguest xguest 4096 Mar 01:06 xguest0-rw-r--r--1 root root 0 Apr 17:07 file1[a-z].10-rw-r--r--1 root Root 0 Apr 17:07 file2[a-z].20-rw-r--r--1 root root 0 Apr 17:07 file3[a-z].30-rw-r--r--1 Root R Oot 0 Apr 17:07 file5[a-z].50-rw-r--r--1 root roOT 0 Apr 17:07 file7[a-z].70-rw-r--r--1 root root 0 Apr 17:07 file6[a-z].60-rw-r--r--1 root root      0 Apr 17:07 file8[a-z].80-rw-r--r--1 root root 0 Apr 17:07 file9[a-z].90-rw-r--r--1 root root 0 Apr 17:27 text1.txt0-rw-r--r--1 root root 0 Apr 17:27 text2.txt0-rw-r--r--1 root root 0 Ap R 17:27 tex[[email protected] home]# find-type f-mmin +3-iname "*[1-9]*"-exec rm-rf {} \; [[email protected] home]# ll-rsttotal drwx------. 4 xguest xguest 4096 Mar 01:06 xguest0-rw-r--r--1 root root 0 Apr 17:27 text1.txt0-rw-r--r--1 root ro      OT 0 Apr 17:27 text2.txt0-rw-r--r--1 root root 0 Apr 17:27 text3.txt0-rw-r--r--1 root root  0 Apr 17:27 text4.txt0-rw-r--r--1 root root 0 Apr 17:27 text5.txt0-rw-r--r--1 root root 0 Apr 20 17:27 text6.txt0-rw-r--r--1 root root 0 Apr 17:27 text9.txt0-rw-r--r--1 root root 0 Apr 17:27 text8.txt0-rw-r--r--1 root root 0 Apr 17:27 text7.txt4 drwxr-xr-x.  2 root root 4096 Apr 17:28 iso[[email protected] home]#

Shell Learning Locate and find commands

Related Article

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.