Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am seeking to remove all special characters from several files' worth of downloaded .pdfs, and came across exactly the solution I was looking for, albeit in an OS X environment:

function to automatically remove special characters from file names during saving in MacOS X.

Could a similar method--either using sed or some other function--be implemented in a Linux environment?

share|improve this question
up vote 10 down vote accepted

You can do this with the rename command. If you are in the folder with the .pdf files with special characters:

rename 's/[^a-zA-Z0-9]//' *.pdf

This will remove any characters from files ending in .pdf that are not A-Z in either case, or numbers. You can add to this list:

rename 's/[^a-zA-Z0-9_]//' *.pdf

This version allows underscores.

share|improve this answer
follow-up question: Would you know how to do this when the filename contains letters that aren't from English alphabet? When I try your commands I get "Can't rename filename: Invalid or incomplete multibyte or wide character" for each file. – user2044638 Jul 12 '13 at 9:56
@user2044638 Are you able to rename these files with a mv? – Paul Jul 12 '13 at 13:28
Yes. Worked for every file I tried it on without problems. – user2044638 Jul 12 '13 at 14:15
Hm, doesn't seem to be working for me. I installed the requisite util-linux package, and while it appears to run, there is no change in file names. Is there documentation for "rename" somewhere? – nitrl Jul 12 '13 at 14:30
@nitrl There are two separate "rename" utilities, one supports regex, the other doesn't. Check your man page to see which one you have. – Paul Jul 13 '13 at 0:24

To handle the whole file name and also multiple files:

  • Add /g to handle the whole file name.
  • Add _to replace with underscore (if required to)
  • Add any additional 'types' of files or individual file names at the end, space separated.

rename 's/[^a-zA-Z0-9_.]/_/g' *mp4 *avi

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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