Converting spaces in filenames to underscores



Linux supports long file names, in some (many?) ways better than windows. However, when I moved over to linux I had tons of files with spaces in the name. This isn’t really a problem usually, but it can be a bit annoying having to enclose the filename in quotes for everything… anyway. Most of these were mp3′s that I had ripped from my collection of cd’s to store on the server. The script I used to automatically play through the music archive had problems dealing with the spaces (and I didn’t want to figure out how to make it work…) so I found another solution….


I found a bash script that basically does the job. It’s very simple and I can’t take credit for writing it, but if you want to convert spaces in filenames to underscores then this is for you…..

#!/bin/bash
for i in $(ls -1 *)
do
rename _ *.$1
done

Basically, it takes the file extension of the files you want to rename as an argument, so to rename files with spaces that are mp3s…. call it like this

$convertspaces mp3

and everything in the current directory get’s “fixed”.

Related Posts

Blog Traffic Exchange Related Posts
  • Drive images - filling free space with zeros So, one of the things I've been doing is drive imaging. I've got 3 systems that are to be identical (based on, of all things Freedos...) So, I thought it was a perfect opportunity to dust off cloning/imaging software. So, I've been using the excellent g4l (ghost4linux) which is now......
  • Linux Permissions Headache Yikes, what an evening..... it started innocently enough in the afternoon. I have an old Mandrake 10.0 server that I was upgrading clamav on (recent security update). While I was at it, I was reviewing the anti-spam setup to see if I could get any better success with filtering junk......
  • Using the command line in linux - part 2 This is part two in a series of "how to use the command line in linux" style articles.... these are intended to be quite basic for those that have not used a command line before.... In part one we logged in (if necessary) and found out about the help command,......
Blog Traffic Exchange Related Websites
  • FREE Amazon S3 Manager FREE Manage Amazon S3 with CloudBerry S3 Explorer Stream Your Cloud After a small rant about how S3 can be a pain to mange, my buddy Andy from CloudBerry offered up a nifty solution, a FREE manager that makes working with S3 easier than FTP. CloudBerry Explorer is a familiar......
  • Release Your Disk Space And Increase Computer Speed You probably have dealt with cleaning your hard drive the hard way: one file at a time. There is nothing more annoying that doing this, especially when you are attempting to consolidate a lot of duplicate information. You could go one file at time and allow the system to add......
  • How do RSS Feeds Work? If you’re confounded by that little orange graphic you see on blogs, it’s time to learn all about RSS and how it can benefit your own blog. Most software packages and content management systems offer RSS capablility, but it’s up to you to implement it. When used properly, RSS feeds......
www.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site