Replacing Text in Multiple Text Files with Shell Linux

To replace text in all files on Linux, you can use a command or a tool written in Perl. The Perl tool, available at, offers several features, including the ability to perform multiple search-replace or query-search-replace operations, process multiple files, and apply user-defined Perl expressions to each line of input files. The tool can also run in interactive or batch mode, backup files, and preserve modes/owner when run as root. Additionally, the tool ignores symbolic links, empty files, write-protected files, sockets, named pipes, and directory names, and can optionally replace lines only matching or not matching a given regular expression. This tool has been extensively used over the years with large data sets.


Linux has a command that can be used to substitute text in all files. You can give it a try by using:

find "/path/mypath" -type f -exec sed -i "s/mypattern/mypattern2/g" {} ;

U880D suggests that there is no requirement to retrieve the corresponding files first using


. Instead,


has the capability to scan and substitute.

Frequently Asked Questions