Thursday, July 04, 2013

Linux - The search bit?

When we talk about file access permissions in Linux, the first couple of things come up in your mind probably are chmod, u(owner), g(group) and o(other). And there are three categories for each gruop: read, write, and execute. They are used in various ways by different functions. But have you ever heard about "search bit"? "search bit" also stands for execure permission bit, the purpose of the bit is whenever you try to open any type of file by name, you must have execute permission in each directory mentioned in the name, including the current directory, if it is implied. For example, to open the file ./test/1.txt, we need execute permission in the directory test. We then need appropriate permission for the file 1.txt itself, depending on how we're trying to open it: read-only, readwrite, and so on.

$ touch 1.txt
$ ll 1.txt
-rw-rw-r-- 1 lxu lxu 0 Jul  4 16:32 1.txt
$ cat 1.txt
$ mkdir test
$ mv 1.txt test
$ ll
drwxrwxr-x 2 lxu lxu   4096 Jul  4 16:32 te
$ cat test/1.txt
$ cat test/1.txt
# Change test permission to 660
$ chmod 660 test
$ cat test/1.txt
cat: test/1.txt: Permission denied

No comments: