Remove all spaces or unwanted characters from the file name

Often, there are multiple spaces or unwanted characters in the file name, and it becomes annoying to access these files from the terminal. We can remove spaces from file name manually, but it becomes a tedious task when there are a large number of files involved. Fortunately, GNU/Linux has a command that solves this problem. This is the “rename” command, Which renames the filenames supplied according to the rule specified as the first argument. Let us understand this with a simple example.

Shown below are the files whose names contain spaces:

Remove all spaces or unwanted characters from the file name

Now, let us remove these spaces using the “rename” command as follows:

It’s that simple, We are done. Now, Let us verify the results:

Remove all spaces or unwanted characters from the file name

Indeed, it has worked. In the above example, the “rename” command specified the rule to replace the space with nothing, i.e., it just removes the space. In the above command, the “g” option implies “global”, i.e., “remove all spaces“. If you want to replace spaces with any other character   for instance, an underscore _ then use the following rule with the “rename” command:

It’s that simple, We are done. Now,

Remove all spaces or unwanted characters from the file name

Vijayan J

Thanks for stopping by guys! I’m Vijayan and Techpulse is my beloved brainchild.
Currently working as a PHP developer in a digital marketing start-up, I’m overly passionate about not just learning new things but also putting those into practice. I swear by a quote I once came across…
‘What separates successful people from unsuccessful people is the former’s ability to execute’.
Feel free to reach out to me if you have any questions, suggestions or feedback. Hoping to see more of you here!