Skip to content
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
The Server Admin
The Server Admin
  • Home
  • Linux
  • Windows
  • About
  • What Powers The Server Admin
  • Home
  • Linux
  • Windows
  • About
  • What Powers The Server Admin
Close

Search

  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Subscribe
Linux

Replace a single string in a large number of files in Unix

By Anthony
July 11, 2025 1 Min Read
0

If you have Perl installed on your system

With Perl, you can make the replacement from the Unix command line prompt. At the prompt, enter:

 perl -pi -e 's/old_string/new_string/g' file_pattern

Replace old_string with the string you want to replace and new_string with the replacement string. Replace file_pattern with the files you want to modify. This can be a shell wildcard, such as *.html. The search is case sensitive and Perl will replace substrings of words. For example, take the following command:

 perl -pi -e 's/temp/tmp/g' *.html

Perl would change every instance of temp it found into tmp (including instances of temporary; it would change them to tmporary because of the temp string in the beginning of the word), but would not change the word TEMP into tmp. If the string has characters Perl or the shell would normally interpret as commands, such as / (a forward slash), < (a less-than symbol), > (a greater-than symbol), or ; (a semicolon), put \ (a backslash) before the character. Take the following replacement string, for example:

 /happy/

To correctly replace it, you would have to escape the forward slashes with the escape character (the backslash) so that the forward slashes aren’t interpreted as commands. Your replacement string would need to be:

 \/happy\/

Author

Anthony

Follow Me
Other Articles
Previous

How To Fix WordPress Asking For FTP Credentials

Next

htaccess enable directory listing

Search

Need a Virtual Server for sysctl testing? Check out our plans!

Popular Posts

  • Mount sFTP folder as local drive
    by Anthony
    June 9, 2026
  • Robocopy Examples
    by Anthony
    February 12, 2026
  • Rsync Command Examples
    by Anthony
    February 10, 2026

Trending

  • Mount sFTP folder as local drive
    by Anthony
    June 9, 2026
  • Adding a GUI to a Server or VPS
    by Anthony
    August 27, 2024
  • Back up to a shared folder with Time Machine on Mac
    by Anthony
    January 4, 2025
  • Backup Your Databases
    by Anthony
    March 24, 2024

Editors Picks

    Send an email:
    mail@example.com

    Call me:
    123-456-7890

    • Facebook
    • Twitter
    • Instagram
    • TikTok
    • LinkedIn
    • Behance
    Copyright 2026 — The Server Admin. All rights reserved. Blogsy WordPress Theme