LinuxQuestions.org
Visit Jeremy's Blog.
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 09-20-2006, 03:16 PM   #1
man_linux
LQ Newbie
 
Registered: Aug 2006
Posts: 19

Rep: Reputation: 0
space in file names


How to get rid of spaces used in filenames.
When i upload some files from windows to linux, some of them are with spaces in file names, while reading or editing that file in shell it doesn’t create problem.

but when i use the file name as some variable and try to use in script then it creates problem, i can even rename the file. any solution for this?
 
Old 09-20-2006, 04:20 PM   #2
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
Are you trying to rename the file from a console, i.e. not in a GUI? The trick to working with filenames that have spaces is to put a \ before each space, like this:

file name.foo = file\ name.foo

So if you wantr to rename it use:

mv file\ name.foo file_name.foo

And for scripting I'm not 100% sure, but I think you could put the file name in quotes: FILE="file name.foo" if that's what you're trying to do.

Good luck
 
Old 09-20-2006, 05:46 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You can also use double quotes around the name of the file: e.g., "my file.txt".
 
Old 09-20-2006, 06:32 PM   #4
fudam
Member
 
Registered: Feb 2006
Distribution: FC
Posts: 86

Rep: Reputation: 15
While Matir is correct regarding the quotes, if you still wish to remove the spaces from your filenames try this in bash (in the directory with the intentioned files):
Code:
for i in *; do mv "$i" $(echo "$i" | tr " " "_"); done;
 
  


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
Spaces in file names JohnKFT Slackware 3 11-09-2004 03:44 PM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 08:13 AM
What are some names of tools for checking disk space aaronruss Linux - Newbie 2 06-08-2004 10:55 PM
Unicode file names!! shivasa Linux - General 3 10-16-2003 10:04 PM
duplicate file names? BajaNick Linux - Software 3 08-25-2003 04:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:39 AM.

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
Open Source Consulting | Domain Registration