Find files under Linux and find common commands for files that contain the specified content. __linux

Source: Internet
Author: User

Each operating system is made up of thousands of different kinds of files. The system itself includes files, users ' own files, shared files, and so on. Sometimes we often forget where a file is on the hard drive.

Looking up a file in Microsoft's Windows operating system is fairly straightforward, as long as you click "Start" on the desktop-"search" to find files and documents on your local hard disk, on the LAN, and even on the internet.

However, users who use Linux are less fortunate, and looking up a file on Linux is a really troublesome thing to do. After all, in Linux we need to use the dedicated "find" command to find the files on the hard disk. Nonsense not to say, the following small dong in detail for you to look at Linux to find files and find files containing the specified content commonly used commands .

Whereis < Program name >
Find the installation path for the software
-B Find only binary files
-M find Help files only
-S only find source code
-u excludes specified type files
-F displays only file names
-B < directory > find binaries under specified directory
-M < directory > Find help files in specified directory
-S < directory > find source code in specified directory

Locate < file name >
Searching for files in the file index database
-D < database path > search specified database
Update file Index Database

Find [path] < expression >
Find Files
-name < expression > Find files by file name
-iname < expression > Find file based on filename, ignore case
-path < expressions > Locating files by Path
-ipath < expression > Find files based on paths, ignoring case
-amin < minutes > Files accessed in the last n minutes
-atime < days > Files accessed in the past n days
-cmin < minutes > Modified files in the past N minutes
-ctime < days > Modified files in the past n days
-anewer < reference files > files that are read later than reference files
-cnewer < reference files > files that have been modified later than the reference file
-size < size > Find files based on file size, Unit b C w K M G
-type < file type > Find files based on file type. B Block equipment c character Equipment D directory p pipeline file f normal file L link s port file
-user < user name > 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 Find empty files

To find the line that matches the specified string from the contents of the file:

$ grep "found string" filename

To find the rows that match a regular expression from the contents of the file:

$ grep–e "Regular expression" filename

Lookup is case-insensitive:

$ grep–i "found string" filename

Find a matching number of rows:

$ grep-c "found string" filename

To find rows that do not match the specified string from the contents of the file:

$ grep–v "found string" filename

Find all text files with the. log extension from the root directory, and find the rows that contain "ERROR"

Find/-type f-name "*.log" | Xargs grep "ERROR"

When the system finds the nginx.conf file, it immediately displays nginx.conf file information on the screen.

Find/-name "nginx.conf"-ls

Find a file under the root directory

Find. -name "Test"

Find a file in a directory that contains a string

Grep-r "ZH_CN".

303i files in all file contents under Circular directory

Find. -type f-exec grep-l "303i" {} \;
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: 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.