Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 realise this might be quite a simple question, but I'm still quite new to the command line and only have a grasp of basic commands.

I've downloaded some lecture presentations (~25 or so) from my University however on doing so they've been named things like...


As you can see they've downloaded with the URL encoding %20 instead of a space.

My question is how to batch rename all of these files so that the %20 is removed and replaced with a space instead?

share|improve this question
My mistake, I tried searching but it must have evaded my efforts. The answers here are pretty useful and well explained though. – Ben May 20 '13 at 21:43
And the question is quite useful in itself when generalised to undo URI encoding. – Stéphane Chazelas May 26 '13 at 16:00
Also covered in the following question: unix.stackexchange.com/questions/159253/… (which to me seems pretty duplicate to this one in some way) – syntaxerror Sep 15 '15 at 22:21
up vote 6 down vote accepted

On Debian and derivatives (including Ubuntu), you could use rename, which applies a Perl expression to each file name.

rename 's/%20/ /g' L*
        |  |  | |   |
        |  |  | |   +--- Files to match
        |  |  | +------- globally
        |  |  +--------- with space
        |  +------------ %20
        +--------------- Substitute

I would consider using underscore instead of space – as it generally makes life easier in the cli world.

To generalise to all URI encoding:

rename 'use URI::Escape; $_ = uri_unescape $_' *%*
share|improve this answer

You can use deurlname from renameutils.

$ ls
$ deurlname L4%20Molecular%20Recognition.pdf
$ ls
L4 Molecular Recognition.pdf

I wrote a script that allows you to rename files in an editor.

You just pass the script a filename and it opens your editor with the filename in it. Then you edit the filename, write, and close the editor.

$ ls
$ viname L4%20Molecular%20Recognition.pdf

  (pretend this is an editor)
$ ls

I also wrote a script that automatically renames files to conform to my preferred naming scheme. When I download files, the first thing I do is call this script on them.

$ ls
$ nf L4%20Molecular%20Recognition.pdf
  'L4%20Molecular%20Recognition.pdf' renamed to 'l4-molecular-recognition.pdf'
$ ls

Be careful with that script. It can do some rather dramatic renames. Use its dry run (nf -n) option before renaming any files.

share|improve this answer

You could use convmv in the directory where you have the files:
To test what the output would be:

convmv --unescape *%20*

To actually rename the files add --notest:

convmv --unescape --notest *%20*
share|improve this answer

Another alternative that doesn't rely on external tools outside of bash:

for old in *; do
    new="${old//+/ }"
    printf -v new '%b' "${new//%/\x}"
    mv -- "$old" "$new"
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.