1

I'm trying to learn about file and directory permissions in unix/linux.

I think I got the general idea, if I want to

cat ~/foo/bar/text.txt  

I need x+r permission on ~, ~/foo, ~/foo/bar, and r permission on ~/foo/bar/text.txt.

But let's say I don't have x permission on ~/foo/bar and that somehow my current directory is ~/foo/bar (maybe root user made su user there), let's say there I type

cat text.txt

from my test, it says I don't have permissions even if I have rwx on text.txt.

So my question is: When I type

cat text.txt

does the system really interpret cat ./text.txt and so checks the current directory permission as well? (I thought that the directories I didn't mention in the path wouldn't be checked for permissions, but maybe the current one is checked neitherways?)

So in this case (my current directory is ~/foo/bar and I want to do cat text.txt) the permissions on ~/foo does not matter but those on ~/foo/bar does?

0

The file open operation does require reading its directory entry for its attributes and physical location, which is stored in the current directory (file).

That is why you are getting the permission issue.

Otherwise, your assumptions are right and the system only accesses the path specified. This would make the file accessible in your sudo example if you simply gave x access to the local directory.

Note that the r permission is not needed to retrieve a directory entry, but it is required to list its contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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