Set file permission without using chmod or umask??
Set file permission without using chmod or umask??
am 11.04.2008 11:00:48 von fazlin
Hi All,
Here is my problem:
I have a script that does the following:
$ cat myscript
find . -name *.c > /tmp/list
$
My default umask value is 022. So the file is created with 644
permission (assume /tmp/list did not exist before).
I need "/tmp/list" file to have 640 permission. As for as i know,
there are two ways of doing it in linux - using umask before my
'find'
statement (or) using chmod after 'find' statement.
Is there any other way to set my required file permission other than
this?
Please give me ur valuable suggestions/help.
Thanks in advance,
Fazlin
Re: Set file permission without using chmod or umask??
am 11.04.2008 11:56:28 von Janis Papanagnou
On 11 Apr., 11:00, fazlin wrote:
> Hi All,
>
> Here is my problem:
>
> I have a script that does the following:
>
> $ cat myscript
>
> find . -name *.c > /tmp/list
> $
>
> My default umask value is 022. So the file is created with 644
> permission (assume /tmp/list did not exist before).
>
> I need "/tmp/list" file to have 640 permission. As for as i know,
> there are two ways of doing it in linux - using umask before my
> 'find'
> statement (or) using chmod after 'find' statement.
And you want to achieve what? - Change file permissions while
your find command is running??
>
> Is there any other way to set my required file permission other than
> this?
What do you intend to do, and why do the existing commands not
suit you?
>
> Please give me ur valuable suggestions/help.
In case you want a temporary or rather locally restricted change
of the permissions you can do that in a subshell
( chmod 0222 ; find ... )
Janis
>
> Thanks in advance,
> Fazlin
Re: Set file permission without using chmod or umask??
am 11.04.2008 12:11:10 von Joachim Schmitz
Janis wrote:
> On 11 Apr., 11:00, fazlin wrote:
>> Hi All,
>>
>> Here is my problem:
>>
>> I have a script that does the following:
>>
>> $ cat myscript
>>
>> find . -name *.c > /tmp/list
>> $
>>
>> My default umask value is 022. So the file is created with 644
>> permission (assume /tmp/list did not exist before).
>>
>> I need "/tmp/list" file to have 640 permission. As for as i know,
>> there are two ways of doing it in linux - using umask before my
>> 'find'
>> statement (or) using chmod after 'find' statement.
>
> And you want to achieve what? - Change file permissions while
> your find command is running??
>
>>
>> Is there any other way to set my required file permission other than
>> this?
>
> What do you intend to do, and why do the existing commands not
> suit you?
>
>>
>> Please give me ur valuable suggestions/help.
>
> In case you want a temporary or rather locally restricted change
> of the permissions you can do that in a subshell
>
> ( chmod 0222 ; find ... )
Don't you mean:
( umask 026 ; find ... )
?
Bye, Jojo
Re: Set file permission without using chmod or umask??
am 11.04.2008 14:06:53 von Janis Papanagnou
On 11 Apr., 12:11, "Joachim Schmitz"
wrote:
> Janis wrote:
> > On 11 Apr., 11:00, fazlin wrote:
> >> Hi All,
>
> >> Here is my problem:
>
> >> I have a script that does the following:
>
> >> $ cat myscript
>
> >> find . -name *.c > /tmp/list
> >> $
>
> >> My default umask value is 022. So the file is created with 644
> >> permission (assume /tmp/list did not exist before).
>
> >> I need "/tmp/list" file to have 640 permission. As for as i know,
> >> there are two ways of doing it in linux - using umask before my
> >> 'find'
> >> statement (or) using chmod after 'find' statement.
>
> > And you want to achieve what? - Change file permissions while
> > your find command is running??
>
> >> Is there any other way to set my required file permission other than
> >> this?
>
> > What do you intend to do, and why do the existing commands not
> > suit you?
>
> >> Please give me ur valuable suggestions/help.
>
> > In case you want a temporary or rather locally restricted change
> > of the permissions you can do that in a subshell
>
> > =A0( chmod 0222 ; find ... )
>
> Don't you mean:
> ( umask 026 ; find ... )
> ?
I didn't inspect the actual numbers[*] - the OP seems capable
to do that himself -, rather tried to understand what the OP
was trying to achieve in the first place.
Janis
[*] Maybe I should have written ( chmod ... ; find ... ) to
illustrate my proposal.
>
> Bye, Jojo
Re: Set file permission without using chmod or umask??
am 11.04.2008 14:24:51 von Joachim Schmitz
Janis wrote:
> On 11 Apr., 12:11, "Joachim Schmitz"
> wrote:
>> Janis wrote:
>>> On 11 Apr., 11:00, fazlin wrote:
>>>> Hi All,
>>
>>>> Here is my problem:
>>
>>>> I have a script that does the following:
>>
>>>> $ cat myscript
>>
>>>> find . -name *.c > /tmp/list
>>>> $
>>
>>>> My default umask value is 022. So the file is created with 644
>>>> permission (assume /tmp/list did not exist before).
>>
>>>> I need "/tmp/list" file to have 640 permission. As for as i know,
>>>> there are two ways of doing it in linux - using umask before my
>>>> 'find'
>>>> statement (or) using chmod after 'find' statement.
>>
>>> And you want to achieve what? - Change file permissions while
>>> your find command is running??
>>
>>>> Is there any other way to set my required file permission other
>>>> than this?
>>
>>> What do you intend to do, and why do the existing commands not
>>> suit you?
>>
>>>> Please give me ur valuable suggestions/help.
>>
>>> In case you want a temporary or rather locally restricted change
>>> of the permissions you can do that in a subshell
>>
>>> ( chmod 0222 ; find ... )
>>
>> Don't you mean:
>> ( umask 026 ; find ... )
>> ?
>
> I didn't inspect the actual numbers[*] - the OP seems capable
> to do that himself -, rather tried to understand what the OP
> was trying to achieve in the first place.
>
> Janis
>
> [*] Maybe I should have written ( chmod ... ; find ... ) to
> illustrate my proposal.
You still miss my main point: chmod vs. umask
Bye, Jojo
Re: Set file permission without using chmod or umask??
am 11.04.2008 14:49:57 von mop2
#Is this a solution?
$ echo >zzz
$ stat -c '%a %s' zzz
644 1
$ stat -c '%a %s' /tmp/mymask /tmp/list
640 0
stat: cannot stat `/tmp/list': No such file or directory
$cp /tmp/mymask /tmp/list;find . -name '*.c' > /tmp/list
$stat -c '%a %s' /tmp/mymask /tmp/list
640 0
640 1243752
$
Re: Set file permission without using chmod or umask??
am 11.04.2008 14:56:19 von Joachim Schmitz
mop2 wrote:
> #Is this a solution?
> $ echo >zzz
> $ stat -c '%a %s' zzz
> 644 1
> $ stat -c '%a %s' /tmp/mymask /tmp/list
> 640 0
> stat: cannot stat `/tmp/list': No such file or directory
> $cp /tmp/mymask /tmp/list;find . -name '*.c' > /tmp/list
> $stat -c '%a %s' /tmp/mymask /tmp/list
> 640 0
> 640 1243752
> $
Yes, if you for some strane reason need to avoid using umask before or chmod
after the file creation, copying an existing one with the correct
permissions and then overwriting that might work. Depends on whether your cp
keeps permissions or offers an option to do that and whter you find a file
with the correcvt permissions.
One question remains? Why not using umask (or chmod)?
Bye, Jojo
Re: Set file permission without using chmod or umask??
am 11.04.2008 15:47:59 von Janis Papanagnou
On 11 Apr., 14:24, "Joachim Schmitz"
wrote:
>
> You still miss my main point: chmod vs. umask
Gaaah!!! - Right you are. Thanks.
|-/
Janis (apparently too tired and ready for the weekend)
>
> Bye, Jojo
Re: Set file permission without using chmod or umask??
am 11.04.2008 18:37:42 von Maxwell Lol
fazlin writes:
> Is there any other way to set my required file permission other than
> this?
Write the file in a directory that has mode 750
Yes, it has permissions 664, but the world cannot read it.
Or use an alias/function/shellscript to change umask for the
duration of the find program execution.