Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cp: cannot create directory : No such file or directory

Tags:

linux

Hi
I am trying to copy a folder from a source to a destination but I am getting the following error:

cp: cannot create directory ‘/home/Workspace/Release/addons/’: No such file or directory 

I entered the following command:

cp -R /home/Workspace/Dev/user1/addons/account /home/Workspace/Release/addons/ 

I tried the same command with different folders and it worked fine.

cp -R /home/Desktop/file_transfer/f1/ff1 /home/Desktop/file_transfer/f2/ 


EDIT :
Q2. When I pass the command in the following code:

import os import re dest = "/home/Workspace/Release/addons/" root = "/home/Workspace/Dev/user1/addons/" f = open("/home/appslab/Desktop/main/FTP/release.conf.text", 'r') for line in f:     filepath = root+line     command = "cp -R "+str(filepath)+"\ "+str(dest)     print(command)     os.system(command) 

I am getting the following error:

~/Desktop/FTP$ sudo python oswalk.py cp -R /home/appslab/Workspace/PythonDevserver/appslab/addons/account  /home/appslab/Workspace/PythonRelease/addons cp: missing destination file operand after ‘/home/appslab/Workspace/PythonDevserver/appslab/addons/account’ Try 'cp --help' for more information. sh: 2: /home/appslab/Workspace/PythonRelease/addons: Permission denied 

The command that I am passing to os.system(), in that the dest is showing up on the next line.
Can anyone tell me what the problem is?
Thank you.
EDIT2:
Permissions for that directory:

drwxrwxr-x 363 user1 user1  16384 Sep 16 21:57 addons 

EDIT3: Fix for Q2 :

command = `str("cp -R ")` + str(filepath)+"\ "+str(dest) 
like image 417
ashwin mahajan Avatar asked Oct 04 '16 08:10

ashwin mahajan


People also ask

How do you fix mkdir Cannot create directory?

Resolving The Problem Simply log in as super user “su” and use “chmod 777” to set the directory permissions of where you wish the rational directory to be created. Once done, you can re-enter the original directory again and the install will continue using the same directory.

Will cp create directories?

Combining the mkdir and the cp CommandsIt has a -p option to create parent directories we need.

Why is there no such file or directory?

log No such file or directory” the problem is most likely on the client side. In most cases, this simply indicates that the file or folder specified was a top-level item selected in the backup schedule and it did not exist at the time the backup ran.

How do I cp a directory?

Copy a Directory and Its Contents ( cp -r ) Similarly, you can copy an entire directory to another directory using cp -r followed by the directory name that you want to copy and the name of the directory to where you want to copy the directory (e.g. cp -r directory-name-1 directory-name-2 ).


1 Answers

It is probably because at least one of the directory of your path (/home/Workspace/Release/addons/) does not exist. cp will not create the addons directory (neither its parents of course), so ensure that the path really exists.

To create the path you can do:

mkdir -p /home/Workspace/Release/addons/ 
like image 90
S. de Melo Avatar answered Sep 23 '22 08:09

S. de Melo