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

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

    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

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

    Default

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

    Perfect, thanks!

  4. #4
    Member
    Join Date
    Dec 2001
    Posts
    1,558

    Default

    You can also use the commands "sed" and "replace" which are usually just as effective.
    Beau Henderson

  5. #5
    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 haze
    You can also use the commands "sed" and "replace" which are usually just as effective.
    thanks, I'm not familar with this can you post a example for changing text for several files in a directory.

  6. #6
    Member isputra's Avatar
    Join Date
    May 2003
    Location
    Mbelitar
    Posts
    593

    Default

    Quote Originally Posted by DWHS.net
    thanks, I'm not familar with this can you post a example for changing text for several files in a directory.
    Yes, i would like to know it too
    It's me ...... It's me ......

  7. #7
    Member
    Join Date
    Dec 2001
    Posts
    1,558

    Default

    Quote Originally Posted by DWHS.net
    thanks, I'm not familar with this can you post a example for changing text for several files in a directory.
    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
    Beau Henderson

Similar Threads & Tags
Similar threads

  1. how to replace the existing files
    By muhammad_ijaz in forum New User Questions
    Replies: 1
    Last Post: 01-19-2010, 08:34 PM
  2. Mass replace of all user-files
    By michalexpromo in forum New User Questions
    Replies: 1
    Last Post: 11-05-2009, 09:06 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. command to find and replace a word in files directory wide
    By DWHS.net in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 02-09-2006, 02:40 PM
  5. How to replace text within 600+ files.
    By nat in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 08-01-2004, 03:42 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube