LinuxQuestions.org
Review your favorite Linux distribution.
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 03-14-2009, 03:52 AM   #1
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Rep: Reputation: 15
Moving file which it's name contain spaces by command line???


I tried to move file which it's name is "Untitled Theme.emerald"
using this command
Code:
 mv Untitled Theme.emerald /home/all/Documents
the result was
Code:
mv: cannot stat `Untitled': No such file or directory
mv: cannot stat `Theme.emerald': No such file or directory
I found that the problem is with the name because it contain spaces

How to fix this problem specially if i want to but command like this in a script?
 
Old 03-14-2009, 04:01 AM   #2
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
You can either use \ to escape spaces, or put the filename in double quotes. Both of the following should work:
Code:
mv Untitled\ Theme.emerald /home/all/Documents
mv "Untitled Theme.emerald" /home/all/Documents
 
Old 03-14-2009, 04:06 AM   #3
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Original Poster
Rep: Reputation: 15
thnk u
but what if the file name is variable or not known?

Code:
 mv $a /home/all
 
Old 03-14-2009, 04:34 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
You can put it in double quotes:
Code:
mv "$a" /home/all
 
Old 03-14-2009, 05:02 AM   #5
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bathory View Post
You can put it in double quotes:
Code:
mv "$a" /home/all
I tried your advice in this script

Code:
mkdir multi
multi2=$(find *.png && find *.jpg && find *.gif )
mv "$multi2" $HOME/multi
but it didn't work...
result is this error message
Code:
mv: cannot stat `bn.png\n586689854.jpg\nnew file home tall.jpg\nThe.Curious.Case.of.Benjamin.Button.DVDSCR.XviD-DEViSE.jpg\nmm.gif': No such file or directory
Note that these files are exist
can any body find what is the cause of this error??
 
Old 03-14-2009, 05:15 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
for files in *.png *.jpg *.gif
do
 # do  something with "$files"
done
 
Old 03-14-2009, 05:30 AM   #7
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ghostdog74 View Post
Code:
for files in *.png *.jpg *.gif
do
 # do  something with "$files"
done
it woks!!
Thank u and thank u all guys...
 
  


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
Use spaces in command line? Geminias Linux - Newbie 2 01-03-2006 07:37 PM
Moving files from the command line adam-red Linux - Newbie 5 12-06-2004 04:42 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
Spaces on command line odd Linux - Software 2 05-22-2004 08:17 AM
moving files and folders thru command line JROCK1980 Linux - General 2 02-16-2004 06:55 PM


All times are GMT -5. The time now is 07:31 PM.

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