You can supplement sed with find to expand your scope to all of the current folder’s subdirectories.
find . -type f -exec sed -i 's/foo/bar/g' {} +
-exec command {} +
This variant of the -exec action runs the specified command on the selected files,
but the command line is built by appending each selected file name at the end;
the total number of invocations of the command will be much less than the number of matched files.
The command line is built in much the same way that xargs builds its command lines.
Only one instance of `{}' is allowed within the command, and (when find is being invoked from a shell) it should be quoted (for example, '{}') to protect it from interpretation by shells.
The command is executed in the starting directory.
If any invocation with the `+' form returns a non-zero value as exit status, then find returns a non-zero exit status.
If find encounters an error, this can some‐times cause an immediate exit, so some pending commands may not be run at all.
This variant of -exec always returns true.
note:
This will include any hidden files.
sed use in recursive directory
于 2022-05-23 17:03:15 首次发布