Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

command to find and replace a word in files directory wide

Discussion in 'General Discussion' started by WebHostPro, Feb 9, 2006.

  1. WebHostPro

    WebHostPro Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,651
    Likes Received:
    15
    Trophy Points:
    318
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    Twitter:
    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 :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. PWSowner

    PWSowner Well-Known Member

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

    replace "flippy" "flipper" -- *

    to replace every occurance
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. WebHostPro

    WebHostPro Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,651
    Likes Received:
    15
    Trophy Points:
    318
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    Twitter:

    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,
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    890
    Likes Received:
    1
    Trophy Points:
    168
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice