Linux Shell – How to Rename Files with Spaces

bashlinuxshell

I named a number of files with spaces in them, and I want to replace the space with _. However, every time I write a command in the shell with the file name (eg Spring 2011), the shell doesn't recognize the file or directory.

What can I do about this? Is there any way to use the unicode character for a space?

Best Answer

Escape the space, e.g. Spring\ 2011, or use quotes, e.g. 'Spring 2011'. In the future, it's typically a bad idea to use file names with spaces in them on any *NIX.

If you've got rename, you can use this:

rename ' ' '_' [filenames...]