Bash: rename all files in directory, replacing all hyphens (-) with underscores (_)

I don’t want to waste time doing things manually when I can run a script that will help me save time and effort.

When using Linux or Mac command line (bash?), if you want to rename all files in your present directory and replace all hyphens - with underscores _, run this command:

And if you want to do the reverse, i.e., replace all underscores _ with hyphens -, run this command instead:

To remove substring from file names, (e.g., remove @3x string), run this:

I had to do this after importing image files with hyphens in their names into my Android project. I can’t use images with hyphens in their names.

Related Posts:

Posts that may be related to "Bash: rename all files in directory, replacing all hyphens (-) with underscores (_)":

Catzie

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

Your email address will not be published. Required fields are marked *