Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to find files and their contents in batches in linux system

Shulou Source: shulou.com Published: 2022-06-01 17:30:40 11月16日 Update

This article mainly explains "how to find files and file contents in batches in the linux system", the content in the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to find files and file contents in batches in the linux system"!

For example, find a keyword in all the php files under the current directory

The code is as follows:

Find. /-name "* .php" | xargs grep 'keyword'

If the content you need to find contains special symbols, such as $, etc., grep needs to add parameters

The code is as follows:

Find. /-name "* .php" | xargs grep-F 'keyword'

File name lookup

File name lookup method:

For example, if we know that a file contains the letters srm, it is possible to find all the files in the system that contain these three letters. Enter:

The code is as follows:

Find / etc-name'* srm*'

This command indicates that the linux system will search the entire / etc directory for all files containing the three letters srm, such as absrmyz,tibc.srm and other eligible files can be displayed. If you also know that the file starts with the letters srm, we can also omit the first asterisk, as follows:

The code is as follows:

Find / etc-name 'srm*'

Some other references

Find-name april* looks for files starting with april in the current directory

Find-name april* fprint file looks for files starting with april in the current directory and outputs the results to file

Find-name ap*-o-name may* finds files that start with ap or may

Find / mnt-name tom.txt-ftype vfat looks for files with the name tom.txt and file system type vfat under / mnt

Find / mnt-name t.txt!-ftype vfat looks for files with the name tom.txt and file system type not vfat under / mnt

Find / tmp-name wa*-type l looks under / tmp for files whose name begins with wa and whose type is symbolic link

Find / home-mtime-2 check files that have been changed in the last two days under / home

Find / home-atime-1 check files that have been accessed within 1 day

Find / home-mmin + 60 check files that were changed 60 minutes ago under / home

Find / home-amin + 30 check files that have been accessed in the last 30 minutes

Thank you for your reading, the above is the content of "how to find files and file contents in batches in the linux system". After the study of this article, I believe you have a deeper understanding of how to find files and file contents in batches in the linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File system content code letter directory key keyword type learning name command beginning file name symbol access special parameter that is idea Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi NVidia Apple MariaDB