Linux SEARCH Command

Source: Internet
Author: User

Grep command:

Grep-I pattern files: searches case-insensitive. Case Sensitive by default,

Grep-l pattern files: only names of matched files are listed,

Grep-l pattern files: Lists unmatched file names,

Grep-W pattern files: match only the entire word, not a part of the string (for example, match 'Magic ', not 'magical '),

Grep-C number pattern files: the matching context displays the rows of [number,

Grep pattern1 | pattern2 files: displays the rows matching pattern1 or pattern2,

Grep pattern1 files | grep pattern2: displays rows that match both pattern1 and pattern2.

Example: grep-I Martin @ Martin-desktop :~ $ Grep shopaction-I Notes/SQL/* # Note: * do not forget

Find command:

Find directory-name keyword

Find/-Amin-10 # search for files accessed in the last 10 minutes in the system

Find/-atime-2 # search for files accessed in the last 48 hours in the system

Find/-empty # search for files or folders that are empty in the system

Find/-group cat # Find the groupcat file in the system

Find/-mmin-5 # search for the files modified in the last 5 minutes in the system

Find/-mtime-1 # search for files modified in the last 24 hours in the system

Find/-nouser # search for files belonging to the void user in the system

Find/-user Fred # search for files belonging to the user Fred IN THE SYSTEM

Find.-maxdepth 2-name Fred

-The purpose of the maxdepth option is to restrict the "find" command to search for files in a directory in descending mode, or to search for directories that exceed a certain level. This slows down the search speed, the search takes too much time. For example, to find a file named Fred in the subdirectory of the current (.) Directory tip, run the following command:

Find/-name "php. ini"-ls

After finding the php. ini file, the system immediately displays the php. ini file information on the screen.

Common find Parameters

-Exec command; find and execute the command

-Fprint file: print the complete file name.

-Fprint0 file: print the complete file name, including Empty files.

-Fprintf file format; format of the printed File

-OK command: run the command for the user, and run the command according to user y.

-Printf format; format of the printed File

-Ls: prints files of the same file format.

Locate command

The locate command is actually another method of writing "Find-name", but it is much faster than the latter because it does not search for a specific directory, instead, search for a database (/var/lib/locatedb) that contains information about all local files. The Linux system automatically creates the database and updates the database once a day. Therefore, the latest changed files cannot be found using the locate command. To avoid this problem, you can use the updatedb command to manually update the database before using locate.

Use instance of the locate command:

$ Locate/etc/SH

Search for all files starting with SH in the etc directory.

$ Locate ~ /M

Search all files starting with m in the user's home directory.

$ Locate-I ~ /M

Search all files starting with m in the user's home directory, and ignore the case.

Recursively search all files in a folder

Find directory name-name. SVN | xargs RM
-RF
Rm-RF: deletes all. SVN files in the directory.

Source: Martin blog [http://www.blags.org/]

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.