Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of permision denied while using mv command?

I am trying to move a file from one directory to other by command line.I used this command

raghul@raghul-Aspire-5750Z:~/temp/newfolder$ mv copy.txt /temp/

I got error like this

cannot create regular file '/temp': Permission denied

Can someone help me to figure this out? I need to move a file from one directory to other.

like image 378
Raghul M Avatar asked Oct 13 '25 02:10

Raghul M


2 Answers

First of all you are using the copy command cp, not the move command mv.

Secondly you are trying to copy the file to a new file named /temp, ie. a file named temp in the / directory. This resides in the filesystem's root directory, which is mostly likely owned by root. Unless you have root permissions you can not write to the root directory.

Given that you are naming the file temp, I assume that you want to move the file to the /tmp directory, for which you will have permission to write to. Do this:

$ mv copy.txt /tmp

This will work only if you also have write permission on the file copy.txt because you need to be able to remove it. If you just wanted to copy the file, just read permission is required.

Otherwise, if you really do wish to move the file to a /temp directory, you can use sudo to do that, provided that you are set up as a sudo user:

$ sudo mv copy.txt /temp
[sudo] password for raghul
like image 193
mhawke Avatar answered Oct 14 '25 17:10

mhawke


I just noticed that you're in a personal directory called ~/temp/newfolder. Is that the temp you're trying to move the file to: your personal one, in which newfolder is in? So you want to move the file up one directory?

Then the problem is that your command is missing the 'personal' tag ~. The command should be:

mv copy.txt ~/temp/
like image 26
John Burger Avatar answered Oct 14 '25 15:10

John Burger