File Search under Linux

Source: Internet
Author: User

Common:

GREP-NR "keyword" searches for all files in the current directory that match the keyword

Grep-nr "keywords" *php search php files for all matching keywords in the current directory

Find-name ' *.php ' |xargs grep ' hello! ' Search all matching keywords "hello!" in the current directory The PHP file

Replace file contents

Sed-i "s/the original string/string to be replaced/g" ' grep "the original string"-RL path "replaces a segment of all files in a path with a string we want to modify

The grep-i pattern files are not case-sensitive to search. Case sensitive by default
Grep-l pattern files lists only the matching file names
Grep-l pattern Files lists mismatched filenames
Grep-w pattern files Match only the entire word, not part of the string (such as matching ' magic ' instead of ' magical ')
Grep-c number pattern files match the context to display the [number] line respectively
grep pattern1 | PATTERN2 files displays rows that match pattern1 or pattern2
grep pattern1 Files | grep pattern2 shows rows that match both PATTERN1 and pattern2


Find-name april* Find files starting with April in the current directory
Find-name april* Fprint file finds files starting with April in the current directory and outputs the results
Find-name ap*-o-name may* Find files that start with an AP or May
Find/mnt-name tom.txt-ftype vfat to find files with the name Tom.txt and file system type VFAT under/MNT
Find/mnt-name T.txt! -ftype VFAT under/mnt to find files with the name Tom.txt and file system type not VFAT
Find/tmp-name wa*-type L Find a file with a type of symbolic link at/tmp that begins with the name WA
Find/home-mtime-2 in/home search for files that have changed in the last two days
find/home-atime-1 checked files accessed within 1 days
Find/home-mmin +60 The files that were changed 60 minutes ago at/home
Find/home-amin +30 Check the files that were accessed last 30 minutes ago

Xargs with grep lookup: Find-name ' *.php ' |xargs grep ' hello! '

File Search under Linux

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.