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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-20-2006, 03:16 PM
|
#1
|
LQ Newbie
Registered: Aug 2006
Posts: 19
Rep:
|
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?
|
|
|
09-20-2006, 04:20 PM
|
#2
|
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274
Rep:
|
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
|
|
|
09-20-2006, 05:46 PM
|
#3
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep:
|
You can also use double quotes around the name of the file: e.g., "my file.txt".
|
|
|
09-20-2006, 06:32 PM
|
#4
|
Member
Registered: Feb 2006
Distribution: FC
Posts: 86
Rep:
|
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;
|
|
|
All times are GMT -5. The time now is 09:39 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|