Replace spaces in a filename with hyphens

rename 's/ /-/g' *
As long as you have perl based rename. You can check: =$ rename --help Unknown option: help Usage: rename [-v] [-n] [-f] perlexpr [filenames] That's the good one.

2
By: depesz
2010-10-23 17:03:54

2 Alternatives + Submit Alt

What Others Think

In case you get 'Artist - Song name' turned into 'Artist---Song-name' you need to compress the extra hyphens.
karol · 658 weeks and 4 days ago
@Karol: if you want to compress (it wasn't mention in original snippet), it's trivial with rename: rename 's/[ -]+/-/g' *
depesz · 658 weeks and 4 days ago
This is really minimalistic. I like it. Just for clarification though, do all distributions have the rename command? I think I might have read somewhere how only a few did.
RaymondCrandall · 658 weeks and 4 days ago
@RaymondCrandall: on ubuntu it comes from perl package. I don't have any other distributions handy, so can't check them.
depesz · 658 weeks and 4 days ago
There are two renames I know of: one is a perl thing, the other one is in util-linux-ng (I'm using Arch Linux) - man 1 rename - much simpler than the perl one.
karol · 658 weeks and 4 days ago
I have Male and female pug puppies. They are 12 weeks old. Both fawn, white and black. They have been home raised around children and other dogs. They are eating soft food and started on hard food. They have papers. Pug Puppies for Sale Near Me
rahimhh21 · 40 weeks and 3 days ago
The Alternative music directory with the data and community was on this they also share the system-generated codes on this. Having access to the information that was at the https://www.huffingtonpost.ca/gloria-kopp/essay-writing-payments_b_14793970.html and I hope it can give us more useful articles like this.
jamesharden · 32 weeks and 1 day ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me USA USA USA USA USA USA Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 31 weeks and 3 days ago
However, they were resource-intensive methods, and cost the webmaster far beyond his budget. There have been many best blogger outreach services https://realbloggeroutreach.com/global-outreach/ occasions where a reform campaign ran out of budget, and had to be abruptly withdrawn
LoraJhon · 25 weeks and 5 days ago
These are a few of the comforts associated with link building for ranking. In the ever-changing universe of net marketing, guest posting is vital to stay ahead of your competition and remain in complete visibility of your inquest demographic. The course of action to blend a quality blogger outreach agency is to take hold of advantage of the SEO services offered by the blog outreach services. Setting your web career up for success, Search Engine Optimization Authority provides you with the quality blogger outreach you need to grow your business in the Internet world.
LoraJhon · 19 weeks and 3 days ago
We are made up of about 70% water and fluid is very heavy, so using pills to remove fluid from your body will make you lose weight initially. The solution though is that you will need to use [url=https://responsiblyrain.com/]cans of water[/url] for most of the extra weight that is important to your body, and then you will gain weight so the weight loss gained is not temporary and sustainable. Water pills should not be used purely as a weight loss tool, but only to treat a medical condition under the supervision of your doctor.
FaithKabanda · 19 weeks and 1 day ago
Internet today have changed many people's lives. It made their lives easy and comfortable. So comfortable that almost everything can be done online like https://www.dreamersandlovers.com/ - socialization, work, pay bills and shop without leaving their homes.
adamsmithh · 13 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: