Permission denied for 'cp' or 'mv' command


#1

Hello,

I’m taking cs50 and I’m a baby to c9.

Why can’t I use the ‘cp’ or ‘mv’ command but I can accomplish by using the GUI? It gives me a ‘Permission denied’.

Am doing something wrong?

Thanks,
João


#2

The files are probably owned by the root user or someone else. How did you get them into your workspace? Can you run ls -la in the folder you’re having trouble in and post the output here. That shows all the files in the folder along with who owns them.


#3

Hey Tim,

I created every file and folder except for ide50.

This is what I get from ls -la

jmpsequeira@ide50:~/workspace/cpabg $ ls -la total 28 drwx-w---- 7 ubuntu ubuntu 4096 Mar 31 18:07 ./ drwxrwxr-x 10 ubuntu ubuntu 4096 Mar 31 18:02 ../ drwx-w---- 2 ubuntu ubuntu 4096 Mar 31 13:40 ch3/ drwx-w---- 2 ubuntu ubuntu 4096 Mar 31 13:40 ch4/ drwx-w---- 2 ubuntu ubuntu 4096 Mar 31 16:56 ch5/ drwx------ 2 ubuntu ubuntu 4096 Mar 31 17:40 ch6/ drwx------ 2 ubuntu ubuntu 4096 Mar 31 18:19 ch7/

Edit: I created them directly on cloud9.


#4

Ok…

So I should always use the prefix ‘sudo’ to execute those commands?


#5

Can you also tell us the full command you’re giving for cp or mv?


#6

hey mutahhir,

I’m very new at this but I think I got it after reading your post and doing a little experiment.

I was placing the ‘/’ ahead of the folder like so:
jmpsequeira@ide50:~/workspace/cpabg $ mv test /ch9

and know I get it like this:
jmpsequeira@ide50:~/workspace/cpabg $ mv test ch9/

Thanks


#7

With /ch9 you were moving it to a folder in your root directory, which is owned by root and would require you to use sudo. Once you change to ch9/ then that was a completely different folder so you were able to move it there because it is not owned by root.


#8

You probably don’t want to use / as that refers to the core root directory of your virtual machine where system files are stored. You want to use ./ which refers to the current directory. So type mv test ./ch9/ instead.