简体   繁体   English

Ubuntu-“ mv”命令将文件重命名为空文件名

[英]Ubuntu - “mv” command renames file to empty file name

I have a simple script to move files between directories. 我有一个简单的脚本,可在目录之间移动文件。 Basically, it is: 基本上是:

mv /dir/* /dir/proc/

saved into a shell script "mvproc.sh". 保存到外壳脚本“ mvproc.sh”中。

For some reason, when I run the script (sh mvproc.sh) the file indeed gets moved, but it does not retain the filename and instead gets just an empty filename. 出于某种原因,当我运行脚本(sh mvproc.sh)时,文件确实被移动了,但是它不保留文件名,而是仅得到一个空文件名。 When I run the same command at the bash prompt, it works fine however. 当我在bash提示符下运行相同的命令时,它工作正常。

This script used to work fine on Debian but we had a hard drive failure and I am now migrating everything over to a Ubuntu machine. 这个脚本曾经在Debian上运行良好,但是我们遇到了硬盘故障,现在我将所有内容迁移到Ubuntu计算机上。

Any idea why this is happening? 知道为什么会这样吗? It seems so simple yet I cannot figure it out. 看起来很简单,但我无法弄清楚。

Many thanks. 非常感谢。

edit... 编辑...

I think I found the solution. 我想我找到了解决方案。 For some reason it was putting in carriage returns and maybe line breaks or something that I could not see while editing the sh script in either Notepad++ or even gedit. 由于某种原因,它导致回车,可能是换行符,或者是在Notepad ++或gedit中编辑sh脚本时看不到的东西。 To solve this, when I open the scripts in gedit, I do a Save As, and select Unix/Linux in the drop down menu towards the bottom. 为了解决这个问题,当我在gedit中打开脚本时,我执行了另存为操作,然后在底部的下拉菜单中选择Unix / Linux。 This hopefully gets rid of the weird carriage returns even though I could not see them. 希望可以摆脱奇怪的回车符,即使我看不到它们。

Hopefully this helps some poor soul like me in the future pulling their hair out over this! 希望这可以帮助将来像我这样的可怜的灵魂,为此拉他们的头发!

Thanks! 谢谢!

Try: mv /dir/file /dir/proc/file 尝试: mv /dir/file /dir/proc/file

You are indeed moving the file, but aren't specifying a destination name. 您确实在移动文件,但未指定目标名称。 Other usages of mv : mv其他用法:

Move and rename: mv /dir/filename /dir/proc/newfilename 移动并重命名: mv /dir/filename /dir/proc/newfilename

Rename: mv /dir/filename /dir/newfilename 重命名: mv /dir/filename /dir/newfilename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM