$ touch myfile $ ls -l total 0 -rw-r--r-- 1 embryo embryo 0 Feb 13 15:40 myfile
$ chmod a+w myfile $ ls -l total 0 -rw-rw-rw- 1 embryo embryo 0 Feb 13 15:40 myfile
chmod g-w myfile
chmod -R a+rw mydir
Note that directories must be executable in order to be accessible. If a directory is not executable, you will
not be able to write or modify files inside it. You will be able to list the file names inside the respective directory,
but you will not be able to see the permissions or the contents of those files.
However, this is only one way of assigning permissions. You may have seen something like chmod 644 myfile or
chmod 555 myfile. This is the second way of settings file and folder permissions, and I will show it below.
$ ls -l mydir/ ls: cannot access mydir/file1: Permission denied total 0 -????????? ? ? ? ? ? file1
OWNER GROUP OTHERS rwx r-x r-x 111 101 101 7 5 5
In this case, rwx is 111, which is binary for octal 7, and 101 is binary for octal 5, hence the notation chmod 755 some_file.
Default umask Permissions
New files and directories will be created with default permissions defined by the umask command. The default
umask is set to 022 on most systems, which means new files will be created with permissions 644 (read and write permissions
for the owner, read permissions for the group and others). New directories will be created with
permissions 755, since a directory needs to be executable in order to access its contents (read, write and execute
permissions for the owner, read and execute permissions for everyone else).
File Types
The first bit in permissions can be:
- - for a regular file
- d for a directory
- l for a symbolic link
- c for a special file
- s for a socket
- p for a named pipe
- b for a block device
Special Modes
Included here are SUID and SGID.
Programs will run with the permissions of the owner.
$ ls -l /usr/bin/passwd -rwsr-xr-x 1 root root 45420 Jul 26 2013 /usr/bin/passwd
Resources