I have a directory structure with files and directories and I like to assign permissions so all the files and directories have read-write permissions for the user and read permissions for the group and, additionally, execution permissions to the directory.
I would like to achieve something like that:
$ ls -l
total 16
-rw-r----- 1 daniel daniel 0 5月 23 16:20 1
-rw-r----- 1 daniel daniel 0 5月 23 16:20 2
-rw-r----- 1 daniel daniel 0 5月 23 16:20 3
-rw-r----- 1 daniel daniel 0 5月 23 16:20 4
-rw-r----- 1 daniel daniel 0 5月 23 16:20 5
drwxr-x--- 2 daniel daniel 4096 5月 23 16:00 a
drwxr-x--- 2 daniel daniel 4096 5月 23 16:00 b
drwxr-x--- 2 daniel daniel 4096 5月 23 15:59 c
drwxr-x--- 2 daniel daniel 4096 5月 23 15:59 d
Best Answer
To give execution (search) permission to directories, but not to files, use:
To assign all the permissions as in your example, use:
-R
changes files and directories recursively, while+X
sets execute/search only if the file is a directory or already has execute permission for some user.r
andw
are of course for reading and writing, respectively.Mode
X
(upper x) is documented in both the traditional manual page1 and the info documentation2.It should also work on other Unix like systems, e.g. FreeBSD, NetBSD or OpenBSD. Quoting from the chmod(1) man page of The Open Group Base Specifications Issue 7, 2018 edition:
1
man 1 chmod
2
info '(coreutils)Conditional Executability'