Reputation: 39
i have unix directory path. this directory contains 5 sub-folders. under each subfolder, i have 10 files (similar). this sub folder means each site or location files.
I want to search a particular number present in each five subfolder.
i am currently using grep command which is useful to find string in a sub folder, but not in all sub folders
grep -l search string *. this is performing for a sub folder. i want to do search for all five subfolders using one single command.
Upvotes: 0
Views: 1069
Reputation: 1726
grep -r
is what you want
man grep
/--recursive
-r, --recursive
Read all files under each directory, recursively, following
symbolic links only if they are on the command line.
Note that if no file operand is given, grep searches the working directory.
This is equivalent to the -d recurse option.
Upvotes: 1
Reputation: 204488
using one single command
- why? UNIX is built on the philosophy of using combinations of the right commands to achieve the best results, why would you want to do something different?
In this case, the UNIX tool to find files is named find
and the UNIX tool to Globally search for a Regular Expression within a file and Print the result is grep
so the right approach for your problem is a combination of find
and grep
, e.g.:
find . -type f -print0 | xargs -0 grep -l regexp
Upvotes: 1