Command to make a script running from every subdir
How is the find command (or else if better) to let us run a script from, i.e. relative to, every subdir under, and including, current working directory ?
illustratio e.g. script is Code:
grep 'foo' * |
Code:
find . -type d -exec sh -c 'cd {}; grep foo *' \; I originally had a much more complex example using "-execdir", but found things were much simpler without it. |
Not sure I follow but you can use -R option in grep to recurse subdirs
|
I believe grep was just an example, not the actual intended command.
|
Run the command 'recursively'.
|
Within the shell script filenames should be in quotes, and exit the cd status should matter.
Code:
find . -type d -exec sh -c 'cd "{}" && grep foo *' \ Code:
find . -type d -exec sh -c 'cd "{}" && pwd' \; Code:
find . -type d -exec sh -c 'cd "$0" && pwd' {} \; Code:
find . -type d -exec sh -c 'cd "$1" && pwd' chdir.sh {} \; |
Quote:
Quote:
As cited, you can run a script using the -exec argument. Does that solve what you're trying to do? If not, maybe a more clear question? |
Code:
grep -R foo |
All times are GMT -5. The time now is 03:51 PM. |