moving a file with spaces in name

廉价感情. 提交于 2021-01-01 05:12:03

问题


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!


回答1:


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.




回答2:


Use \ \ to put in white spaces. So

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

should work




回答3:


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




回答4:


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

Like vim "file to open"

:)



来源:https://stackoverflow.com/questions/11738484/moving-a-file-with-spaces-in-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!