Reputation: 1
I lost few files while trying to run mv in unix script.
Command in script
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/
I did bash -x <filename>
while running, the command appeared like below
+ 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'
Please see \r
in the end.
Now I do not find the files in source or destination path.
Please help
Upvotes: 0
Views: 290
Reputation: 4841
All those files except the last are irretrievably lost. They are written to a file named \r
, or the line feed character. Only the last file to be mv
-ed can still be found. You can give it a more readable name by doing mv $'\r' more_readable_name
.
The reason is because the script failed.sh
apparently has been stored with the Windows conventions of text files. Under Unix, a new line is literally the \n
character. Under Windows, it is two characters: \r\n
. This means that you did not write to the intended directory, but to the file \r
in the directory.
For the future, configure your editor to adhere to the UNIX line endings, and/or run the utility dos2unix
on the file.
Upvotes: 3