Execute the ls -l
to list the permissions, owner, and group for all files and directories in a particular directory:
ls -l /var
ls -l /var/www
ls -l /var/www/folder1
ls -l /var/www/folder/folder2
index.html will be included in the listed contents of the last directory so no command is necessary.
Although, if you did want to know the ownership and permission of that file:
ls -l /var/www/folder/folder2/index.html
File permissions are listed in the following format for files:
-rwxrwxrwx
indicates read, write, and execute permissions for everybody.
for directories:
drwxrwxrwx
The first rwx
indicates read, write, execute permission for owner of the file.
The next three characters, rwx
, indicate read, write, execute permission for all users in the group listed for the file.
The last three characters, rwx
, indicate read, write, execute permission for all users.
Together, you have -rwxrwxrwx
, three groups of letters with three letters in each group.
The following command example would allow full permission for the owner of the file, read only for other members of the group, and read only for any other user (-rwxr--r--
):
chmod 744 /var/www/folder/folder2/index.html
Alternatively, if you want to apply permissions to all files and directories in a particular directory, use the -R flag to apply the permissions recursively throughout the directory:
chmod -R 744 /var/www/folder/folder2
or, to apply permissions to all contained files and recursively to all subdirectories:
chmod -R 744 /var/www/folder/folder2/*
The number 7
coincides with rwx
.
The number 6
coincides with rw-
and does not allow permission to execute.
The number 5
coincides with r-x
and does not allow permission to write.
The number 4
coincides with r--
read-only.
The number 3
coincides with -wx
and does not allow permission to read.
The number 2
coincides with -w-
and is write-only.
The number 1
coincides with --x
and is execute-only.
One common combination is 664 which gives read and write to the owner and group members for the file, read only for all other users and no permission for executing the file: -rw-rw-r--
chmod
recursively with the numeric syntax is bad, because it sets the "x" permission to the same for directories and files. It's better to use letter syntax egchmod -R g+w .
to add group write permission, leaving the "x" permission unchanged. – thomasrutter Jul 23 '15 at 07:01x
permission on a directory doesn't allow to list the content, but allows entering it. This is useful for~/public_html
, where the web server user needs to go through your home directory topublic_html
, so you can use..1
permissions to allow that without allowing anyone to list your home directory – Simon Richter Jul 23 '15 at 13:01