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??

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..

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?

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 ----------

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).

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.

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 !!