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

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

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