LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   mv command with files name include spaces (https://www.linuxquestions.org/questions/linux-software-2/mv-command-with-files-name-include-spaces-835957/)

a.albreiki 10-03-2010 01:45 PM

mv command with files name include spaces
 
Dear all

one system send files to linux machine and it is name contains spaces and i tried to move it from one directory to other,but it show error

ex:-

mv -f file one file two
mv: target `one' is not a directory

-------

that is all :(

H_TeXMeX_H 10-03-2010 02:45 PM

Use quotes:

First type:
Code:

mv 'Large File Na
press Tab and it should auto-complete it:

Code:

mv 'Large File Name'
then put the destination directory. You can use either single or double quotes, but single quote is safer so that bash wont interpret anything in the quotes.

a.albreiki 10-04-2010 01:37 AM

Hi H_TeXMeX_H,

Thanks alot,

it is work in command shell.

but is not work in bash script please any advice

This is from my bash script and it is work with for loop and it is fine when i show the result with echo. but when applied mv command show that error

#--------------------------------------------------------------------
mkdir -p /nfs04/archive/${DIR}/${year}/${month}/${day}/
mv -f '{$FILE}' /nfs04/archive/${DIR}/${year}/${month}/${day}/.
sleep 5
#---------------------------------------------------------------------

THIS IS THE RESULT OF set -x
+ mkdir -p /nfs04/archive/A_BCD_EFG_Disk0/2010/10/03/
+ mv -f '{A-BCD-EFG-Disk 0-201010031330-4095.SSS}' /nfs04/archive/A_BCD_EFG_Disk0/2010/10/03/.
mv: cannot stat `{A-BCD-EFG-Disk 0-201010031330-4095.SSS}': No such file or directory
+ sleep 5
#-----------------------------------------------------------------------

Regards

jdkaye 10-04-2010 01:44 AM

I think using backslash-space should work in a script. Suppose your file is called "my file". Then you could try
Code:

mv my\ file newfile
this should rename "my file" as "newfile". I've done this often on the command line but never tried it in a script.
ciao,
jdk

a.albreiki 10-04-2010 02:43 AM

Quote:

Originally Posted by jdkaye (Post 4116913)
I think using backslash-space should work in a script. Suppose your file is called "my file". Then you could try
Code:

mv my\ file newfile
this should rename "my file" as "newfile". I've done this often on the command line but never tried it in a script.
ciao,
jdk


Thank you,

but i use bash script and file name save in parameter

and the files has different name for that i can't add backslash-space for it.

H_TeXMeX_H 10-04-2010 04:44 AM

Try:

Code:

mkdir -p "/nfs04/archive/${DIR}/${year}/${month}/${day}/"
mv -f "{$FILE}" "/nfs04/archive/${DIR}/${year}/${month}/${day}/."
sleep 5


a.albreiki 10-05-2010 04:46 AM

Quote:

Originally Posted by H_TeXMeX_H (Post 4117011)
Try:

Code:

mkdir -p "/nfs04/archive/${DIR}/${year}/${month}/${day}/"
mv -f "{$FILE}" "/nfs04/archive/${DIR}/${year}/${month}/${day}/."
sleep 5




Thanks H_TeXMeX_H very much and it is work well.

Regards


All times are GMT -5. The time now is 11:16 PM.