LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Moving file which it's name contain spaces by command line??? (https://www.linuxquestions.org/questions/linux-general-1/moving-file-which-its-name-contain-spaces-by-command-line-711528/)

Mr.mick-duck 03-14-2009 03:52 AM

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?

bathory 03-14-2009 04:01 AM

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


Mr.mick-duck 03-14-2009 04:06 AM

thnk u
but what if the file name is variable or not known?

Code:

mv $a /home/all

bathory 03-14-2009 04:34 AM

You can put it in double quotes:
Code:

mv "$a" /home/all

Mr.mick-duck 03-14-2009 05:02 AM

Quote:

Originally Posted by bathory (Post 3475110)
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??

ghostdog74 03-14-2009 05:15 AM

Code:

for files in *.png *.jpg *.gif
do
 # do  something with "$files"
done


Mr.mick-duck 03-14-2009 05:30 AM

Quote:

Originally Posted by ghostdog74 (Post 3475137)
Code:

for files in *.png *.jpg *.gif
do
 # do  something with "$files"
done


it woks!!
Thank u and thank u all guys...


All times are GMT -5. The time now is 12:23 PM.