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.

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:
    1
    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:
    38
    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.
     
  3. kebirhost

    kebirhost Member

    Joined:
    Jan 9, 2005
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    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:
    38
    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!
     
Loading...

Share This Page