script demo
find ./ -type f -exec grep -l "tmp" {
} +
script explanation
tmp
To find files or paths that contain a specific string with one command in Linux , you can use grep
commands combined with find
commands. Here is an example command:
find /path/to/search -type f -exec grep -l "tmp" {
} +
Please /path/to/search
replace 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 find
to find files, and -type f
the parameters indicate that only ordinary files are found, and directories and other types of files are excluded. The arguments are then -exec
used to execute grep
the 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.