mv命令

时间:2016-05-06 06:31:30

标签: unix mv

我尝试在unix脚本中运行mv时丢失了一些文件。

脚本命令

user:/opt/app/intech_collected1/ccp > head failed.sh
#!/bin/bash
mv in4_G_004_0086147809_20160503_008.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_001_0005027604_20160504_001.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_008_0008299443_20160504_007.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_008_0008301379_20160504_007.s /opt/app/intech_directory/intech_polled/ccp/
mv R_0_3_10-1_0_1_0_0_160504033902_008.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_002_0001115247_20160504_002.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_001_0086147949_20160504_008.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_008_0086145465_20160503_008.s /opt/app/intech_directory/intech_polled/ccp/
mv in4_G_002_0086095468_20160503_008.s /opt/app/intech_directory/intech_polled/ccp/

我做了bash -x <filename>

运行时,命令如下所示

+ mv in4_G_001_0008315698_20160505_007.s $'/opt/app/intech_directory/intech_polled/ccp/\r'
+ mv in4_G_001_0086037914_20160504_008.s $'/opt/app/intech_directory/intech_polled/ccp/\r'
+ mv in4_G_008_0008299994_20160504_007.s $'/opt/app/intech_directory/intech_polled/ccp/\r'
+ mv in4_G_008_0086161387_20160504_008.s $'/opt/app/intech_directory/intech_polled/ccp/\r'
+ mv in4_G_002_0001115198_20160504_002.s $'/opt/app/intech_directory/intech_polled/ccp/\r'
+ mv in4_G_008_0086161432_20160504_008.s $'/opt/app/intech_directory/intech_polled/ccp/\r'

最后请参阅\r

现在我找不到源路径或目标路径中的文件。

请帮忙

1 个答案:

答案 0 :(得分:3)

除了最后一个文件之外的所有文件都无可挽回地丢失了。它们将写入名为\r的文件或换行符。只能找到最后一个mv - ed的文件。您可以通过mv $'\r' more_readable_name为其提供更易读的名称。

原因是因为脚本failed.sh显然已与Windows文本文件约定一起存储。在Unix下,新行实际上是\n字符。在Windows下,它是两个字符:\r\n。这意味着您没有写入目标目录,而是写入目录中的文件\r

将来,请将编辑器配置为遵循UNIX行结尾,和/或在文件上运行实用程序dos2unix