Computing.Net > Forums > Linux > Replacing spaces in filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Replacing spaces in filename

Reply to Message Icon

Name: B
Date: April 11, 2003 at 01:53:47 Pacific
OS: 9.0
CPU/Ram: P 4
Comment:

Hello,

I have hundreds of files that contain spaces. I want to have a script that will replace these spaces with a hyphen or something similar. Any ideas? I started by writing a bash script:

for i in `ls`
do
.....
done

but, i gets split up like this (for example):
The original file name is Christmas Eve 001.jpg

so, $i gets set to Christmas, Eve, 001.jpg separately. Any help is greatly appreciated!!!!!!!!!!

Brian



Sponsored Link
Ads by Google

Response Number 1
Name: 3Dave
Date: April 11, 2003 at 02:33:08 Pacific
Reply:

Just use the "rename" command:
# rename foo bar /*.doc
will replace all instances of "foo" in file
names with "bar" for all ".doc" files,
eg: foofoo.doc -> foobar.doc

The command you want will be something like:
# rename " " "_" ./*


0

Response Number 2
Name: B
Date: April 11, 2003 at 12:42:49 Pacific
Reply:

Dave - You are the man!!! Thank you!! This one has had me stumped for a while...


0
Reply to Message Icon

Related Posts

See More


Servers and firewall ques... Booting with Redhat 9 cd



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Replacing spaces in filename

How to double space in open office. www.computing.net/answers/linux/how-to-double-space-in-open-office/22362.html

how to determine free space in cd www.computing.net/answers/linux/how-to-determine-free-space-in-cd/29352.html

No such file in Redhat 9 www.computing.net/answers/linux/no-such-file-in-redhat-9/20455.html