Common commands for finding files and file contents in Linux

Source: Internet
Author: User

First, Whereis < program name > find Software Installation path
-B finds only binary files-m only find help files
-S find source code only
-U excludes the specified type file
-F Show file name only
-B < directories > Find binaries in the specified directory
-M < directory > Find help files in the specified directory
-S < directory > find source code under specified directory

Second, locate < file name >
Searching for files in the file index database
-D < database path > search for specified database
UpdateDB
Update file Index Database

Third, find [path] < expressions >
Find Files
-name < expressions > Find files by file name
-iname < expressions > Find files by file name, ignoring case
-path < expressions > Find files by Path
-ipath < expressions > Find files by path, ignoring case
-amin < min > Files accessed in the last n minutes
-atime < days > Files accessed in the last n days
-cmin < minutes > modified files in the last n minutes
-ctime < days > Files modified in the last n days
-anewer < reference files > files that have been read later than the referenced file
-cnewer < reference files > files that have been modified later than the referenced file
-size < size > Find files based on file size, Unit b C w K M G
-type < file type > Find files by file type. B Block device c character device D catalog p pipe file f normal file L link s port file
-user < username > Find files by attribution user
-uid <uid> Find files by uid
-group < Group name > Find files by attribution Group
-gid <gid> find files by gid

-empty Finding empty files

The system immediately displays httpd.conf file information on the screen after finding the httpd.conf file.
Find/-name "httpd.conf"-ls

Find a file under the root directory
Find. -name "Test"

Iv. grep command
Find matches the specified string from the file contents of the line $ grep "The string being looked up" file name
Find the line that matches the regular expression from the file contents:
$ grep–e "Regular expression" file name
Find is case insensitive:
$ grep–i "string found" file name
To find the number of matching rows:
$ grep-c "string found" file name
Find rows that do not match the specified string from the file contents:
$ grep–v "string found" file name

From the root directory, look for all text files with a. log extension and find the line that contains "ERROR"
Find/-type f-name "*.log" | Xargs grep "ERROR"

Find a file containing a string in a directory
Grep-r "ZH_CN".

Common commands for finding files and file contents in 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.