Four common file search commands in linux

Source: Internet
Author: User

Four common file search commands in linux
1. File SEARCH Command locate (locate, search)
The greatest benefit is high speed.
Format: locate file name
Path of the returned File
Search Method: search by file name in the background database, updated every day
Therefore, it takes the next day to search new files.
However, you can also forcibly update the database and execute the updatedb command.
Database location/var/lib/mlocate (different versions have different locations)
Configuration File:/etc/updatedb. conf, which specifies some directories.
Do not participate in search such as/etc/temp
Disadvantage: search by file name only
Example: locate javatest
2. SEARCH Command whereis and which
Location of the whereis SEARCH command, not the file
-B: Only view the executable file location
-M: only view the location of the help document
The location where the which SEARCH Command is located. You can also view aliases without searching for files.
Search echo $ path in PATH Environment
Example: whereis ls which ls
3. find (all searches, each file name)
Powerful but resource-consuming
Therefore, try to avoid a wide range of queries
Format: find search range Search Condition
Find/-name test search in the root directory
The search content must be the same as the file name.
If you want to search for more information, you need to perform fuzzy match (*). The matching content is written in "".
* Match any content (multiple characters)
? Match any single character
[] Match any character in brackets
Option parameters:
-Name: By file name
-The iname file name is case insensitive.
-The user searches for find/root-nouser Based on the owner and no owner file exists.
Generated by the kernel. All files other than external files must have owners.
-Mtime: searches for objects modified at the specified time.
-Atime: Find the file to be accessed at a specified time
-Ctime: Find the file whose attribute is changed at the specified time.
Parameter-10 10 days + 10 10 days before 10 10th days (note that all are past tense)
-Size: File size
Find.-size + 25 k (+ 25 k is greater than 25 k MB is upper case M not written Unit indicates data block (sector data block 512 byte). Identify the current directory)
-Inum searches for files based on the specified I Node
-Both a (and) logic and two conditions are met
-O (or) logic or
-Exec (add the second command in the middle, such as ls, rm-rf) {}\; the result of command 1 is processed by command 2.
Example:
Find.-name test
Find.-name test.gz
Find.-name "*" All
Find.-name "*. gz" all files in this directory end with gz
Find.-atime-10
Find.-size-10 KB or less
Find.-size-100 M more than 10 M
Find.-size-10 k-a-atime-10
Find.-size-10 k-a-atime + 10
Find.-name "*"-a-size-10 k-exec ls-lhi {}\; (\ must have spaces before)
4. grep
Format: grep option string file name search for string lines containing keywords in the file
Regular Expression matching required for matching
Example: grep "size" File Name
-V Inversion
If the search matches a file name, the wildcard is used for full match.
Search for the content in a file and use a regular expression to include matching
Example:
Grep "log" install. log
Difference between find and grep
Find is to find matching files
Grep is the matching string in the file.

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.