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!

Need a file renamer script

Discussion in 'General Discussion' started by kebirhost, Jul 17, 2006.

  1. kebirhost

    kebirhost Member

    Joined:
    Jan 9, 2005
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    151
    Hello,

    I need to rename many files in a directory recursively. I have a scripts renaming the files but it does not work recursively. The script is below;

    ###################
    # renames.sh
    # basic file renamer

    criteria=$1
    re_match=$2


    for i in $( find ./ -name *$criteria* );
    do
    src=$i
    tgt=$(echo $i | sed -e "s/$criteria/$re_match/")
    mv $src $tgt
    done
    ######################


    If you have this kind of scripts but working recursively, please post here. Thanks for all.

    Melih
     
  2. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    Try:

    Code:
    find . -type d -exec sh -c "cd {}; /blah/blah/renames.sh \;"
    where /blah/blah is where the renames.sh script lives.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. kebirhost

    kebirhost Member

    Joined:
    Jan 9, 2005
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    151
    Hi,

    Thanks so much but it gives an error as;

    find: missing argument to `-exec'

    I am not an expert so sorry for any misunderstanding.

    Melih
     
  4. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    Check the manual page for find, I'll have made some small/stupid error with the bit after the -exec ...

    Sorry for not checking, lack of time prevented it!
     
    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