Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a folder udp_folder2

d------r-T 41 root           root     4096 Apr 26 21:17 udp_folder2

when I'm with user other than root, I can't cp -r it into a new folder it says: Permission denied

why? and how can I copy it with a user other than root

share|improve this question

4 Answers 4

up vote 4 down vote accepted

Well,

That would be because the way your current permissions are set, no one can move that file. ( Other than root, because root doesn't follow the same rules. )

You would need to either change the owner of the file (chown), OR add the other user to the group 'root' and chmod it so the group can execute on the directory, OR allow everyone else to execute the file.

So, a quick fix would be:

chmod -R o+rwx udp_folder2

That will give everyone the ability to read, write and execute on that directory.

Also... if you're attempting to copy 'udp_folder2' into the same directory that it is located now, you'll need the 'w' permission on that directory as well. For example:

/foo/udp_folder2 - you'll need 'w' on /foo to copy that directory in /foo

I'd suggest learning linux file permissions: Linux File Permission Tutorial

share|improve this answer
    
I think copy is just r permission, obviously there is r permission for other user, you see, there is a r –  user138126 Apr 26 '13 at 23:13
    
I mean in d------r-T , the r is for other user –  user138126 Apr 26 '13 at 23:19
1  
You also need execute permission to copy a directory. I'm not sure what T is offhand. –  Swiss Apr 26 '13 at 23:31
    
You'll need the 'w' on the directory you're trying to copy to... for example, if you're copying /home/foo to /etc/foo you'll need the 'w' permission in /etc/ –  Tillman32 Apr 26 '13 at 23:33
2  
@Swiss - The 'T' is a sticky bit, which is a 'special' permission. Learn all about sticky bits here: en.wikipedia.org/wiki/Sticky_bit –  Tillman32 Apr 26 '13 at 23:48

The directory has no x permission, so others (i.e., in this case any user) can use the directory to reach the files inside. The T means it is sticky (only the owner of a file can delete it). With both the x permission and the sticky bit, you would see a lowercase t; the uppercase T says “no access permission but sticky bit, which is an odd combination”.

Read up on Unix file/directory permissions. It isn't too hard, and you will need it.

share|improve this answer

You don't want to give everyone rwx on the directory because you'd create a security risk. And you wouldn't want to -R the chmod because that would write changes recursively.

Just chmod 755 "filename" and you're good.

Here's a break down of the numbers:

  • Read = 4
  • Write = 2
  • Execute = 1

Then you have 3 groups:

  • Owner.
  • Those who belong to the Group.
  • Everyone else.

So, if you want to give the owner rwx, those who belong to the group rw, and everyone else rw you just add the permissions: rwx = 7, because r+w+x is 4+2+1 and rw = 6 because r+w = 4+2.

share|improve this answer
    
Hence my term 'So, a quick fix would be' and I send him a link to learn more about permissions. He didn't mention a concern for security or anything of the sort. He just stated that he wants to copy the directory. –  Tillman32 Apr 26 '13 at 23:37
    
Also, we he'll need the 'w' permission on the directory he's attempting to copy it into. –  Tillman32 Apr 26 '13 at 23:43
    
Don't be a hater Tillman. –  mister mister Apr 27 '13 at 0:23

To copy folder where owner doesn't have permission to it, you've to change these permissions.

If the folder is restricted even for the owner, there is some reason for it and giving the permissions for everyone else (o) isn't a good solution (as shown in the first answer).

For folder to be accessed by the owner, it needs to have read (r) and execute/search bits (X) set. If you've folders within the folders, each one should follow the same rules. For files only read bit (r) is enough.

So basically to give the reading permissions to the folder recursively, you've to run:

chmod -vR u+rX folder/

If you're running above command as a user, prefix with sudo (if you've superuser privileges), otherwise run as root.

If some files within the folder aren't owned by root, change it recursively by:

sudo chown -vR root folder/

Then copy it as usual or use rsync as follow:

rsync -vuar src/ dst/

For more explanation about above commands, check: man chmod and man chown.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.