CentOS finds a directory or file and displays the keywords in the file

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


copy code
code show as below:

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



If the content to be searched contains special symbols, such as $, etc., grep needs to add parameters


copy code
code show as below:

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



File name search

File name search method:

For example, we know that a file contains the three letters of srm, then to find all the files containing these three letters in the system can be realized, enter:


copy code
code show as below:

find /etc -name '*srm*'



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


copy code
code show as below:

find /etc -name 'srm*'



Some other references

find -name april* Find files starting with april in the current directory
find -name april* fprint file Find files starting with april in the current directory and output the result to file
find -name ap* -o -name may* find files starting with ap or may
find /mnt -name tom.txt -ftype vfat find files under /mnt with name tom.txt and filesystem type vfat
find /mnt -name t.txt ! -ftype vfat Find a file named tom.txt under /mnt and the file system type is not vfat
find /tmp -name wa* -type l Find a file named wa and whose type is a symbolic link under /tmp
find / home -mtime -2 Check files under /home that have been changed in the last two days
find /home -atime -1 Check files that have been accessed within 1 day
find /home -mmin +60 Check 60 minutes ago under /home Changed files
find /home -amin +30 Check files that have been accessed in the last 30 minutes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070004&siteId=291194637