Welcome to the Linux Hosting Talk.
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2011
    Location
    Dublin, PA
    Posts
    1,138
    Rep Power
    10

    Linux search and replace string in multiple files recursively

    I had to search and replace a string today and figured i'd post it up here in case it'll help someone..

    I cloned a site for a client and had to replace some hardcoded paths in their millions of (seems like) files.. here is what I used to get it done quickly:

    Code:
    find /home/newuser/public_html/ -type f -exec sed -i 's,\/home\/olduser,\/home\/newuser,g' {} \;
    That may look a little funny because I had to escape the forward slashes.. and use a different separator because of the slashes - here's an easier one:

    Code:
    find /home/newuser/public_html/ -type f -exec sed -i 's/oldstuff/newstuff/g' {} \

 

 

Similar Threads

  1. dedicated servers with multiple IP's
    By messi in forum VPS and Dedicated Server Hosting
    Replies: 11
    Last Post: 02-21-2013, 04:37 AM
  2. Run a command on multiple Linux servers
    By Rob in forum On the Server
    Replies: 0
    Last Post: 10-10-2012, 02:49 PM
  3. Search Wikipedia Through CLI (Shell) In Linux
    By Rob in forum Linux Articles
    Replies: 0
    Last Post: 03-27-2012, 09:34 AM
  4. Upload files with ssh / scp in Linux
    By Rob in forum Linux Articles
    Replies: 1
    Last Post: 01-13-2012, 06:44 AM
  5. Tar up only certain types of files
    By Rob in forum On the Server
    Replies: 0
    Last Post: 08-23-2011, 12:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


» Our Friends

Powered by vBadvanced
Back to top