I have a large list of files in many folders. Some files are causing issues so I need to rename the parentheses to something else , anything else.

I am trying to use these commands to find any and all files with either "(" or ")".

Obviously this wouldn't work:

find . -name *(*

I need to escape the "(" character:

find . -name *\(*


find . -name '*\(*'


find . -name "*\(*"

Neither of the above works.

In the end, I want the following to work:

`find . -name '*.*' -prune -o -exec rename 's/\*/(*$/\OOOO/i' {} +`  

The above should rename any "(" character to 0000 (eg. Document(July).xls would change to Document0000July).xls)


find . -name '*.*' -prune -o -exec rename 's/\*/)*$/\1111/i' {} +

this should rename any ")" character to 1111 (eg. Document0000July).xls would change to Document0000July1111.xls)

any ideas?



a simple and quite portable solution (but could choke on special filename cases... a more robust one could be cooked up if you have a recent version of GNU xargs and find):

find . \( -name '*(*' -o -name '*)*' \) -print > ze_list
while read a_line ; do 
   echo mv "$a_line" "$(echo "$a_line" | sed -e 's/(/0000/g' -e 's/)/1111/g')" ; 
done < ze_list

Then if you are confident it would do what you want, take out the 'echo'

(don't worry as the shell is hiding the surrounding quotes (") when using echo, but they will be there to ensure "mv" receives 2 arguments only, a source, and a destination.)

the "$(....|....)" is where the replacement appears. The surrounding quotes are important so that the resulting name, even if it contains spaces, will still be considered one (1) argument.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.