File permission by chmod


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File permission by chmod
# 1  
Old 04-14-2010
File permission by chmod

Hi,

I have a typical problem. Consider the scenario:

Folder1
------> Folder2 ------> File1
------> Folder3

Above is my folder structure, currently the user group "other" has no permissions. I wish to give "read" permission for "others" to File1 using a single command.

chmod -R o+r Folder1 # gives permission to even Folder3 as well which I don't want.

Only way I could find to give permission is to give permission "r" for each of Folder1, Folder2 and File1. Problem becomes complex if there are 10 folders to recurse.

Any solution??
# 2  
Old 04-14-2010
If you want to give "read" permission for "others" to File1 only and you know its complete path name then you can use :

chmod o+r /Folder1/Folder2/File1

its preety clear...
or...
else I am not getting you..
# 3  
Old 04-14-2010
If I understand -
You have to grant at least --x access to others for the directories above File1 on up -> root directory, otherwise others will never get down to the leve where others can even see File1.

This means you have to grant r-x or at least x to all of the directories involved, then grant r-- to File1. IS this what you are asking?
# 4  
Old 04-14-2010
Quote:
Originally Posted by Reboot
If you want to give "read" permission for "others" to File1 only and you know its complete path name then you can use :

chmod o+r /Folder1/Folder2/File1

its preety clear...
or...
else I am not getting you..
Thanks for suggestion. The above command sets permission for read only for File1. But not on Folder1 and Folder2. So others won't be able to navigate to reach the file. Also, I found that we need to have execute 'x' as well to navigate. So,

chmod o+rx /Folder1/Folder2/File1 # sets permission for just File1 not the folders.

---------- Post updated at 05:50 AM ---------- Previous update was at 05:48 AM ----------

Quote:
Originally Posted by jim mcnamara
If I understand -
You have to grant at least --x access to others for the directories above File1 on up -> root directory, otherwise others will never get down to the leve where others can even see File1.

This means you have to grant r-x or at least x to all of the directories involved, then grant r-- to File1. IS this what you are asking?
Yes, you are right, we have to provide both 'r' and 'x' for folders to navigate. But in order to do so I have to execute many chmod commands till the File1 (imagine the scenario where we may have 10-15 Folders).
# 5  
Old 04-14-2010
What you said is correct - you have to execute a LOT of commands.
You can create a sort of recursive loop using dirname, but do NOT use chmod -R as you already know.
Code:
path=/this/is/a/long/pathname/to/File1
chmod o+r $path
path=$(dirname $path)
while [[ $path != "/" ]]
do
    chmod o+x $path
    path=$(dirname $path)
done

If you have NSF mountpoints or links in the path it might break this code or your filetree. For example, links on Solaris are created as rwxrwxrwx.
# 6  
Old 04-15-2010
Bug

Quote:
Originally Posted by jim mcnamara
What you said is correct - you have to execute a LOT of commands.
You can create a sort of recursive loop using dirname, but do NOT use chmod -R as you already know.
Code:
path=/this/is/a/long/pathname/to/File1
chmod o+r $path
path=$(dirname $path)
while [[ $path != "/" ]]
do
    chmod o+x $path
    path=$(dirname $path)
done

If you have NSF mountpoints or links in the path it might break this code or your filetree. For example, links on Solaris are created as rwxrwxrwx.
This looks like brilliant hint. Will test and let you !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Permission denied error using chmod on a cifs mount

I have a RHEL 5.7 system with a cifs mount from a Windows 2007 file server that I need to fix the permissions on. Once the share is mounted the permission for the mount are 777. I need to change that to 770 on the top level directory and to 640 on the sub-directory .ssh/. But when I run chmod... (0 Replies)
Discussion started by: westmoreland
0 Replies

2. Shell Programming and Scripting

Change the permission to previously used in unix ( chmod )

I have changed the premission of a file to 777. Now I would like to change permission to previously used ( UNDO ). Is there any command ?:confused: (3 Replies)
Discussion started by: frintocf
3 Replies

3. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

4. UNIX and Linux Applications

What is the difference between chmod in solaris and chmod in Linux?

i think it is the same in both... Iam i right? (1 Reply)
Discussion started by: sumaiya
1 Replies

5. UNIX for Dummies Questions & Answers

chmod of remote file

I would like to chmod the file which I am pulling from remote server onto my server. I am using the following script: sftp <server detail> get abc xyz chmod 666 xyz bye Though I could fetch the file successfully but I am not able to change the permission of xyz file on my server. umask... (1 Reply)
Discussion started by: kdtrica
1 Replies

6. UNIX for Dummies Questions & Answers

CHMOD....read only permission

After creating a user account...how do i verify if theres only read access on the account. If not read access would i enter chmod a-xw "username"? (2 Replies)
Discussion started by: bigben1220
2 Replies

7. AIX

Permission denied when rm or chmod

I got "Permission denied" error message when I rm or chmod a file. I'm the owner of the file "lice_20091123.tar". How can I solve this matter? lice@appl:/midasapp/lice> whoami lice lice@appl:/midasapp/lice> who am i guest pts/12 Nov 23 19:09 (ooo.ooo.ooo.oo) ... (3 Replies)
Discussion started by: kang
3 Replies

8. Programming

chmod:No such file or directory

sprintf(fname, "core.%d", pid); (void) unlink(fname); if (ttrace(TT_PROC_CORE, pid, 0, 0, 0, 0) != 0) { perror("TT_PROC_CORE pass"); Fail(); } if (chmod(fname, 0) != 0) { perror("chmod"); Fail(); } Hi, If i execute above code,everytime am getting below... (1 Reply)
Discussion started by: mansa
1 Replies

9. Shell Programming and Scripting

use a file to chmod

Hi! I need help becouse I've server to backup and I've a lot of files with 700 permission and I need to change the mode to 755 before copy So the point is. With find . -perm 700 -exec echo {} > textfile.txt \; I got a text file with 3156 line which one... (3 Replies)
Discussion started by: ruben.rodrigues
3 Replies

10. UNIX for Advanced & Expert Users

change permission chmod

Hi, when I launch my perl script, I write on the shell: perl x.pl How I can can change the permission to write only: x to launch the program? (2 Replies)
Discussion started by: Minguccio75
2 Replies
Login or Register to Ask a Question

Featured Tech Videos