3

I have a file in unix with name as "this is my file.xls"

I want to move it from one folder to other. I wrote the below lines:

fileName="this is my file"
myDate=20121125

mv $FIRST_DIR/"${fileName}.xls" $SECOND_DIR/"${fileName}_${myDate}.xls"

However, this is not working. I am getting error as "file.xls is not a directory"

What is the correct way to do this?

Thanks for reading!

Vicky
  • 16,679
  • 54
  • 139
  • 232

4 Answers4

6

Use escape characters for spaces. So change the variable fileName to "this\ is\ my\ file". This ensures that the shell will ignore the spaces and won't consider it as a delimiter.

Amal Antony
  • 6,477
  • 14
  • 53
  • 76
1

In mac, you don't need to use symbol \. Simply put the complete filename with space inside double quotes to open.

Like vim "file to open".

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
Parveen Verma
  • 16,690
  • 1
  • 14
  • 19
0

Use \ \ to put in white spaces. So

mv this\ \is\ \my\ \file this-is-my-file 

should work

Drew
  • 24,851
  • 10
  • 43
  • 78
0

this should work mv this.is.my.file.xls Make sure you put a backlash in front of the dots