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!

How do you do a find and replace for all the files in a directory?

Discussion in 'General Discussion' started by WebHostPro, Apr 14, 2005.

  1. WebHostPro

    WebHostPro Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,660
    Likes Received:
    16
    Trophy Points:
    318
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    Twitter:
    It's been a while sorry but I forgot how.

    grep /folder something *

    I don't know am I even close?

    Just to be clear, I have a directory with thousands of files and one term on every file I need changed to something else.

    Thank you for you help.

    Chaze
     
    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
    Here are some samples of batch file renaming that I saved from somewhere.

    # change .htm files to .html
    for file in *.htm ; do mv $file `echo $file | sed 's/\(.*\.\)htm/\1html/'` ; done

    # change .html files to .htm
    for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1htm/'` ; done

    #change .html files to .shtml
    for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1shtml/'` ; done


    A modification of this looks like what you want.
     
    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,660
    Likes Received:
    16
    Trophy Points:
    318
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    Twitter:

    Perfect, thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. haze

    haze Well-Known Member

    Joined:
    Dec 21, 2001
    Messages:
    1,550
    Likes Received:
    3
    Trophy Points:
    318
    You can also use the commands "sed" and "replace" which are usually just as effective.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. WebHostPro

    WebHostPro Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,660
    Likes Received:
    16
    Trophy Points:
    318
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    Twitter:
    thanks, I'm not familar with this can you post a example for changing text for several files in a directory.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. isputra

    isputra Well-Known Member

    Joined:
    May 3, 2003
    Messages:
    575
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Mbelitar
    Yes, i would like to know it too ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. haze

    haze Well-Known Member

    Joined:
    Dec 21, 2001
    Messages:
    1,550
    Likes Received:
    3
    Trophy Points:
    318
    This is where man pages usually come in handy ;)

    replace "old-string" "new-String" -- *.ext
    replace "old-string" "new-String" -- *
    replace "old-string" "new-String" -- filename
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
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