In my external hard drive, there are about 1TB of data (PDFs, plain text docs, pictures, binary execuatables etc.). The data was created in Windows 10 and the hard-drive is formatted NTFS.

Starting from the root of the hard drive, I would like to recursively descend into each folder and replace the spaces in all files with underscore to make it easier to work with them from the terminal.

I saw the question here: and thinking of using the top answer there

 rename 'y/ /_/' * 

from the root of my external hard drive.

However, that thread does not have a high view count and only 2 members have upvoted the answers. Being a novice, I am a little concerned if there might be any inherent issues in this. Is there a better way to handle this issue of cross-platform ease of working at the terminal ? (maybe advice like 'do this only for plain text files, or some other problems that I am not able to foresee')


1 Answer 1


I think it will work for you, but stay alert for the following problems that may arise:

  1. You may overwrite some files (ex: if you have 'some_file.txt' and 'some file.txt', the first one will be overwritten (lost).
  2. The rename command is not recursive. If you have many directories and sub-directories, you will need to figure out a way to do it (script, or using find, as pointed by @centimane find ./ -exec rename 'y/ /_/' {} \;).
  3. If you have some applications and lib files, they may stop work if they can't find the renamed files anymore (same for saved .html pages, for example).

    It is a good idea to try the command first in a sub directory with a copy of some of the files.

obs: Sorry about the English. It is not my native language...

  • 1
    I can help you with point #2: find ./ -exec rename 'y/ /_/' {} \;. You can see man find if you're wondering about the -exec syntax.
    – Centimane
    Commented Feb 17, 2017 at 20:24
  • Good point. Find will be straightforward. Commented Feb 20, 2017 at 11:43

Not the answer you're looking for? Browse other questions tagged .