Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    cPanel Partner NOC cPanel Partner NOC Badge DWHS.net's Avatar
    Join Date
    Jul 2002
    Location
    LA, Costa RIca
    Posts
    1,356

    Lightbulb command to find and replace a word in files directory wide

    I need to replace word everywhere in the files in the home directory.

    For example the word flippy needs to be flipper for every file.

    Anyone know the command for find and replace words in all files directory wide?

    Thanks, Steve

  2. #2
    Member PWSowner's Avatar
    Join Date
    Nov 2001
    Location
    ON, Canada
    Posts
    2,994

    Default

    cd to the directory you want, then

    replace "flippy" "flipper" -- *

    to replace every occurance
    Mike
    WHM and cPanel Scripts (join our "Scripts Club")
    D/A Photography

  3. #3
    cPanel Partner NOC cPanel Partner NOC Badge DWHS.net's Avatar
    Join Date
    Jul 2002
    Location
    LA, Costa RIca
    Posts
    1,356

    Default

    Quote Originally Posted by PWSowner
    cd to the directory you want, then

    replace "flippy" "flipper" -- *

    to replace every occurance

    Great thanks, also do you know how to go into sub directories like this as well.

    So /home/all/folders get checked for the word and replaced in each file.

    Thanks,

  4. #4
    Member
    Join Date
    Mar 2004
    Location
    This Planet
    Posts
    984

    Default

    I often use following format.

    grep -rl 'flippy' * | xargs perl -p -i -e 's/flippy/flipper/'


    But with care:

    check if you get the right files with:

    grep -rl 'flippy' * (say while you are within /home )

    If yes, then run the full cmd

    Anup

Similar Threads & Tags
Similar threads

  1. find word in the files & search
    By crazyaboutlinux in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 02-04-2010, 07:37 AM
  2. how to replace the existing files
    By muhammad_ijaz in forum New User Questions
    Replies: 1
    Last Post: 01-19-2010, 08:34 PM
  3. Find and replace via SSH
    By marquis_ce in forum New User Questions
    Replies: 1
    Last Post: 04-21-2008, 11:53 AM
  4. how to find large files using command line linux?
    By spaceman in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 08-29-2006, 12:22 AM
  5. How do you do a find and replace for all the files in a directory?
    By DWHS.net in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 04-14-2005, 08:49 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube