The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

command to find and replace a word in files directory wide

Discussion in 'General Discussion' started by DWHS.net, Feb 9, 2006.

  1. DWHS.net

    DWHS.net Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,569
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    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. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    cd to the directory you want, then

    replace "flippy" "flipper" -- *

    to replace every occurance
     
  3. DWHS.net

    DWHS.net Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,569
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator

    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. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    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
     
Loading...

Share This Page