LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-17-2003, 06:57 PM   #1
rooster13
LQ Newbie
 
Registered: Jul 2003
Posts: 5

Rep: Reputation: 0
replacing space in filenames


is there any way to replace spaces in filenames with, for example, '_'?? I have a whole bunch of files that origin from the windows world, and my bash scripts aren't working well with the "space" characters in filenames. Thanks for your time.
 
Old 07-17-2003, 07:17 PM   #2
linuxlah
Member
 
Registered: Jun 2002
Location: Batu Puteh, Malaysia
Distribution: (Mandrake 8.2) (Redhat 7.2,8.0,9.0) (Slackware 9.0,9.1)
Posts: 154

Rep: Reputation: 30
try this bash script

PHP Code:
for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done 
 
Old 07-18-2003, 04:35 AM   #3
rooster13
LQ Newbie
 
Registered: Jul 2003
Posts: 5

Original Poster
Rep: Reputation: 0
So, since I'm such a rookie with these bash scripts, I have to ask if this script would do the work (replace all spaces in directory and file names with '_' in all subdirs of the directory it runned from)

#!/bin/bash

ROOTDIR=$(pwd)
DIRS=$(find . -type d)
for d in $DIRS; do
cd $d
for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done
cd $ROOTDIR
done

Last edited by rooster13; 07-18-2003 at 05:13 AM.
 
  


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
how to reduce swap space and reclaim the space grantm Linux - Newbie 7 08-16-2012 07:05 AM
notify user space application from the kernel space lordofring Linux - Software 2 06-22-2009 12:32 PM
replacing all spaces in filenames of a directory merlin23 Linux - Newbie 1 01-11-2005 07:52 AM
Not enough space for root directory on a drive with 50g free space??? auoq Linux - Newbie 1 10-13-2004 12:44 PM
\ before space in filenames using gnome terminal ? cozye Linux - General 1 12-09-2003 01:44 PM


All times are GMT -5. The time now is 12:21 AM.

Main Menu
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