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.

Mass rename files on server

Discussion in 'General Discussion' started by foreigndude, Jul 10, 2006.

  1. foreigndude

    foreigndude Member

    Joined:
    Aug 16, 2005
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Hi all,

    Don't know where to go with this, but I could not find anything on this subject on this forum.

    I'm a WHM/Cpanel user and one of my sites is running on php-Nuke. I noticed that my security configuration blocks all users that click on a file whose filename contains parenthesis [e.g., Artist Name - My first song (2005-2006).mp3].

    So, what I'm trying to do is mass rename all the files that have "(" and/or ")" in their filename. Basically, I need a way to replace "(" and ")" with a space or "-" or anything else, to prevent the security system from blocking the users.

    Thoughts?

    I know this can be done through shell somehow, but I'm not sure how to do it. Any help will be greatly appreciated!
     
  2. nxds

    nxds Well-Known Member

    Joined:
    Jan 6, 2006
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    6
    Here's one way of doing it. This renames files from the current directory down (not dirs) with ('s or )'s replacing ( with { and ) with }. Change the tr command if you want to have different characters substituted (e.g. tr -- '()' '--' to replace with -'s).

    PHP:
    find . -type f --regex '.*[()][()]*[^/]*' | while read name; do base=$(basename "$name"); dir=$(dirname "$name"); newbase=$(echo "$basetr -- '()' '{}'); echo mv "$name" "$dir/$newbase"done
    Remove the echo before mv to actually rename files.
     
  3. foreigndude

    foreigndude Member

    Joined:
    Aug 16, 2005
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Awesome. Thank you!
     
Loading...

Share This Page