LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-12-2001, 02:27 AM   #1
ebone
LQ Newbie
 
Registered: Nov 2001
Posts: 2

Rep: Reputation: 0
spaces in filenames


what can i do to get rid of (or replace with an underscore) the spaces in filesnames copied from from my windows box to a linux box

TIA

E
 
Old 11-12-2001, 12:51 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,688
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Code:
#!/bin/sh
cdir=pwd
if [ ! -d "$1" ]; then
echo $1 must be dir
exit 1
else cd "$1"
for f in $(/bin/ls * | grep " "); do
nwName=$(echo "$f" | sed -e "s/ /_/g")
mv "$f" "$nwName"
done
cd $cdir
fi
Im running Bash on Linux and Windows, so this should work crossplatform, just check before deploying it, and use quotes or backslashes when entering wintendo dirnames with spaces.
It's a kinda crude solution, but it works for me.

Save this as something like "spc2uscore.sh" and invoke with the path+dirname as the single argument, changes every filename with spaces in that dir to filenames with underscores.

HTH somehow.
 
Old 11-12-2001, 12:56 PM   #3
ebone
LQ Newbie
 
Registered: Nov 2001
Posts: 2

Original Poster
Rep: Reputation: 0
thanks, i'll give it a try

E
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
filenames with spaces antony.booth Programming 5 11-01-2005 05:49 AM
How to use foreach on filenames with spaces? BrianK Linux - General 3 08-09-2005 01:15 PM
ls and filenames with spaces rose_bud4201 Programming 10 07-01-2005 09:28 AM
Spaces in filenames with BASH edenning Programming 12 01-27-2005 08:10 AM
filenames with spaces - explain t3___ Linux - Newbie 14 02-17-2004 07:13 PM


All times are GMT -5. The time now is 03:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration