Find and Replace text in all files in a directory and all subdirectories
If looking like replacing text in multiple files in a single line of command, have reached the right place. Many times we need to find or make changes to a given text and to start or do not know which file, document or folder may be.
Let's say you change the server IP address, and we must make the changes in all configuration files and logs where you see the old IP.
Not to be searching for hours among all the files from our server, I pass these tips to replace alphanumeric strings in linux.
- To replace a text or string each time it appears in the files:
- To replace the first time it appears the text:
- To replace all files in a directory:
deathbian: ~ # find / path / dir "*. txt" | xargs perl-pi-e 's / text / replacement / g'
deathbian: ~ # find / path / dir "*. txt" | xargs perl-pi-e 's / text / replacement /'
deathbian: ~ # for arg in `ls-C1`; do perl-pi-e 's / text / replacement / g'; done;
There are a lot of combinations possible using the shell command line. Take the first search:
deathbian: ~ # for arg in `find / your / home / dir-name" *. txt "`; do perl-pi-e 's / text / replacement / g' $ arg; done;
Popularity: 12%
10 Comments
Trackbacks
- Find and replace multiple files in a directory. - Galego
- Find and replace multiple files in a directory.
- Find and Replace multiple files directory dun. - Galego






























Two days ago I'm looking for something that allows me to do this, thank you
What a great help! Indeed glad to know that there are professional people dedicated to helping others. Thank you very much for the contribution. (b): D (ci)
To replace email addresses in the configuration of exim use;
find / etc / exim / * | xargs perl-pi-e 's / user \ @ dominio.com / / g'
and with that I delete the user address in N documents.
perl-pi.bak-e "s / favicon.ico / fernando.ico / g;" for the file configuration.php configuration.php and replace with fernando.ico favicon.ico
must know how to write and explain what enl browser question
as I use where I have to put a little expliken
Here I give you one that replaces encontrre massive lines of text in many kinds of archivoo for TexFinderX xp 2.14 for Windows XP and Vista