Reputation: 53
I am trying to copy a file under path:
dir1/dir2/dir3/file
into a directory with path:
dir7/dir9/dir10
I am using the cp command like this:
cp dir1/dir2/dir3/file dir7/dir9/dir10
But I get the error:
cannot create regular file 'dir7/dir9/dir10': No such file or directory
But the directory definitely exists. I am so confused, what am I doing wrong?
Upvotes: 0
Views: 142
Reputation: 451
You are getting an error because dir10 does not exist. Linux is trying to copy a file into a folder that has not yet been created. You will have to run the following command first:
mkdir -p dir7/dir9/dir10
cp dir1/dir2/dir3/file dir7/dir9/dir10
Upvotes: 0
Reputation: 556
Always use absolute directory paths if you are not certain about relative path.
In your case, if dir7/dir9/dir10 lies in / directory then provide full path to cp command like,
cp dir1/dir2/dir3/file /dir7/dir9/dir10
if it lies in /home/usr/ directory then provide it as,
cp dir1/dir2/dir3/file /home/usr/dir7/dir9/dir10
This applies to first argument also,
cp <absolute path> <absolute path>
Upvotes: 3