![]() |
strange (to me) behavior of file permissions when copying file
I wish that when copying a file, it has the attributes defined by umask. This sometimes happens, other times do not:
$ls -l /bin/cat -rwxr-xr-x 1 root root 44072 11 set 13:18 /bin/cat $umask 0002 $cp /bin/cat mycat ; ls -l mycat -rwxr-xr-x 1 rob rob 44072 22 ott 17:51 mycat The date have been updated, but the permissions don't (the group can't write). Now if I try with: $umask 0077 $cp /bin/cat mycat ; ls -l mycat -rwxr-xr-x 1 rob rob 44072 22 ott 17:52 mycat $rm mycat $cp /bin/cat mycat ; ls -l mycat -rwx------ 1 rob rob 44072 22 ott 17:52 mycat Worked! Note that I had to delete the file in order to have the right permissions set. It seems that umask is followed only if it is more restrictive than the original file. Is there any way to force umask for copied files? I also tried with: $rm mycat $umask 0002 $cp --no-preserve=all /bin/cat mycat ; ls -l mycat -rwxr-xr-x 1 rob rob 44072 22 ott 18:00 mycat but it doesn't work either!!! |
Hi there, i agree your issues seem strange, but copy is not really the right command to install and setup file permissions in one command.
The install command is much better ... [neil@f11 tmp]$ touch nhi [neil@f11 tmp]$ install -m 777 nhi nhi2 [neil@f11 tmp]$ ls -l nhi* -rw-rw-r-- 1 neil neil 0 2009-10-22 19:51 nhi -rwxrwxrwx 1 neil neil 0 2009-10-22 19:51 nhi2 |
Using install is a nice workaround. I wish to understand if the behavior of umask is a bug or a programmers' choice. Moreover, I can not use install when using scp or a filemanager such as dolphin or konqueror.
There should be a way to automatically set the default permissions to new files, also when copied. |
Quote:
Code:
$ cp -p path1 path2Code:
$ scp -p path1 path2-p: Preserves modification times, access times, and modes from the original file. |
Quote:
This is what I DON'T want to do: I do not want to preserve permissions BUT I wish to use those from umask. |
Hey Warrob
It appears that this is not an issue with umask i think it is really cp that was holding you up, using --remove-destination works. [root@f11 tmp]# cp /bin/cat /tmp/ [root@f11 tmp]# ls -l /tmp/cat -rwxr-xr-x 1 root root 57096 2009-10-23 22:28 /tmp/cat [root@f11 tmp]# umask 0077 [root@f11 tmp]# cp /bin/cat /tmp/ cp: overwrite `/tmp/cat'? y [root@f11 tmp]# ls -l /tmp/cat -rwxr-xr-x 1 root root 57096 2009-10-23 22:33 /tmp/cat [root@f11 tmp]# man cp [root@f11 tmp]# cp --remove-destination /bin/cat /tmp/ cp: overwrite `/tmp/cat'? y [root@f11 tmp]# ls -l /tmp/cat -rwx------ 1 root root 57096 2009-10-23 22:34 /tmp/cat |
Quote:
So, to answer your original inquiry: Quote:
Have you considered just setting permissions on all the copied files rather than trying to trick the system into behaving as though the files are newly created? This is safer than deleting then copying, for a reason that should be obvious.
|
Quote:
if I set umask 0077 , this will affect the copied file (even without --remove-destination) but with umask 0002 the original permissions are retained. That's weird to me! |
Quote:
|
Quote:
Code:
$ man umaskThe user file-creation mask is set to mode. If mode begins with a digit, it is interpreted as an octal number; otherwise it is interpreted as a symbolic mode mask similar to that accepted by chmod(1). If mode is omitted, the current value of the mask is printed. The -S option causes the mask to be printed in symbolic form; the default output is an octal number. If the -p option is supplied, and mode is omitted, the output is in a form that may be reused as input. The return status is 0 if the mode was successfully changed or if no mode argument was supplied, and false otherwise. Remember "umask" is a mask, not a value. Think about what that means. In the example you chose, the copied file has to be created, which means it's a new file. And the source umask has no effect on the destination, which was my point. Your example shows that the destination umask sets default permissions on newly created files, which is what it's for. |
Quote:
Besides, any idea on why the --no-preserve option in cp does not work? |
| All times are GMT -5. The time now is 01:14 AM. |