Can't copy, move, rename files that have special character (single quote) in their file names

gb flag

I have some files that have the special character ' in their file names. I seem to not able to copy, move, rename those files.

For example, when I try to rename grandpa's_pen.mp4 to grandpas_pen.mp4, the action takes too much time.

The size of the files is about 50MB and my hard disk is NVMe.

Any idea why this happens?

ca flag

You need to escape ', since, as you have also mentioned, single quotes (') are special characters in Bash (which is most likely the shell your terminal uses). To escape a character you can use the escape character \ right in front of it. So, for example, to rename grandpa's_pen.mp4 to grandpas_pen.mp4 you should run:

mv grandpa\'s_pen.mp4 grandpas_pen.mp4

Alternatively, you can use double quotes (") around the files that have single quotes. The above example would be in that case:

mv "grandpa's_pen.mp4" grandpas_pen.mp4


You said:

For example, when I try to rename grandpa's_pen.mp4 to grandpas_pen.mp4, the action takes too much time.

In this case that action does not take too much time. Simply, the command has not even run!

That's because when single quotes and double quotes are used as special characters, that is when they are used without being escaped, they are expected by the shell to be in pairs.

In your case, grandpa's_pen.mp4 has one unescaped single quote, so when you press Enter to run your command, the shell gives you a new prompt, in which you could type more text, and waits until you enter a closing single quote. Only if you enter that closing single quote and press Enter will the command run, which is almost certain to return an error.


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.