Copying file to destination directory overwrites directory with file

file-copysolaris

A script which runs on Solaris uses cp to copy a single file into a destination directory.

On occasion this cp command will overwrite that destination directory with the file being copied

For example when trying to move test.txt to the directory /home/user/Dest:

cp /home/user/Docs/test.txt /home/user/Dest

the entire Dest directory becomes a text file with the contents of test.txt which has been renamed Dest.

I am able to get around this issue by using:
cp /home/user/Docs/test.txt /home/user/Dest/test.txt

What could be causing this issue?

Best Answer

I guess you should issue:

cp /home/user/Docs/test.txt /home/user/Dest/ 

instead of

cp /home/user/Docs/test.txt /home/user/Dest 

The / at the end means the destination is a directory not a file.

Related Question