Linux command: Find files containing the string tmp in the current directory

script demo

find ./ -type f -exec grep -l "tmp" {
    
    } +

insert image description here

script explanation

tmpTo find files or paths that contain a specific string with one command in Linux , you can use grepcommands combined with findcommands. Here is an example command:

find /path/to/search -type f -exec grep -l "tmp" {
    
    } +

Please /path/to/searchreplace with the directory path you want to search. This command will recursively search for files containing a string in the specified directory and its subdirectories tmp, and output matching file paths.

The command is used here findto find files, and -type fthe parameters indicate that only ordinary files are found, and directories and other types of files are excluded. The arguments are then -execused to execute grepthe command to search the file contents. grep -l "tmp"command is used to search for a string in a file and output the matching file paths.

Note that this command will recursively search the entire directory tree, so it may take some time if the searched directory is large or the number of files is large.

Guess you like

Origin blog.csdn.net/a772304419/article/details/132718136