The title says it all and yes I know there are many questions similar, but the closest I could find was removing " and not '. What I've tried so far is:

find -name "*'*" -type f | rename 's/\'//g'

or rename 's/[']//g' and some other variations. I find all the files, but when I'm piping it to rename, I'm just getting >for prompt and have to Ctrl+C to return. I've recently changed a lot of files with this, and it has worked like a charm on any special character, except the single quotes.


You can use double quotes:

rename -n "s/'//g"

remove -n after testing to rename the files for real

Use -exec though...

find -name "*'*" -type f -exec rename -n "s/'//g" '{}' \;

If the list is not too long, make it faster...

find -name "*'*" -type f -exec rename -n "s/'//g" '{}' +

Or, as suggested in comments, use recursive shell globbing:

shopt -s globstar
rename -n "s/'//g" **/*"'"*

You can use shopt -u globstar to turn recursive globbing with ** off, but it will be off anyway when you start a new shell.

  • The rename command has its own file globbing syntax, so there's likely no need for the find command here. – Tom Russell Sep 5 '20 at 1:13
  • @TomRussell oh really? I don't know about that - I use the shell to glob with rename (there is globstar which would presumably work here). Would you care to post an answer to demonstrate? – Zanna Sep 5 '20 at 2:04
  • The final parameter is the standard shell globbing: Usage: rename [options] <expression> <replacement> <file>... – Tom Russell Sep 6 '20 at 9:51
  • Oops. I neglected to consider the recursive aspect of the OP's question. – Tom Russell Sep 8 '20 at 5:18
  • @TomRussell that output looks like it comes from the other rename (rename.ul) command to me. I am not familiar with that command, but I did not find anything about rename having its own globbing syntax (the way find does). Bash has globstar which makes ** recursive, but one has to quote the single quote again... shopt -s globstar; rename -n "s/'//g" **/*"'"* is working for me in Bash 5.0.17 – Zanna Sep 8 '20 at 5:33

This works with bash on my system (OpenSUSE Leap):

$ rename "'" '' **

The 3 args to rename are: "'", '' and ** (globstar), telling it to replace the quote with the empty string and do so recursively.

Note that ** (globstar) is turned on by default on my system. I'm not aware of a way to turn it off.

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.