To find out more about file permissions I highly recommend run a terminal (Ctrl + Alt + T) and do some examples. Go to the folder within your home directory find a folder which contains a few files and folders.
type: ls -l and hit Enter
and we will get an output as an example below.
Most commons ls with different flags:
ls (is used to show files and/or folders in the current directory)
ls -l (details of files/folders)
ls -al (details of files/folders with hidden items)
ls -d */ (directories only)
ls * (list with sub-directories)
ls -ltr (list of items sorted by time in reverse order)
Example from terminal:
peter@peter-linux:~/PycharmProjects/training$ ls -l drwxrwxr-x 2 peter peter 4096 Dec 29 11:14 Folder -rw-rw-r-- 1 peter peter 528 Dec 27 20:05 main.py -rw-rw-r-- 1 peter peter 64 Dec 28 21:47 maths_task.py -rw-rw-r-- 1 peter peter 486 Dec 28 21:45 odd_minute.py drwxrwxr-x 2 peter peter 4096 Dec 27 21:32 __pycache__ -rw-rw-r-- 1 peter peter 386 Dec 27 21:38 random_test.py -rw-rw-r-- 1 peter peter 199 Dec 27 21:21 test_median.py
Split example for each section:
First method
Syntax: chmod [options] reference operator permission FileName
[options]: -R (change directory and all files it contains)
reference: u (owner), g (group), o (others), a (all)
operator: + (adds mode), – (removes mode), = (set for one reference)
permission: r (read), w (write), x (execute)
Examples for better understanding.
Command | Results |
chmod a+rwx main.py | file main.py has added rights to read, write and execute for all users |
chmod a-x main.py | file main.py has removed rights to execute for all users |
chmod u=rwx main.py | file main.py has added rights to read, write and execute for owner no changes for the rest |
chmod g=rx main.py | the group can read and execute a file main.py |
chmod -R g+rx Folder | the group has added rights to read and execute to Folder and all items inside |
Second method
Second method based on Octal numbers system. Octal represents 8 digits (0-7).
-rw-rw-r-- 1 peter peter 528 Dec 27 20:05 main.py EXAMPLE 1 peter@peter-linux:~/PycharmProjects/training$ chmod 764 main.py -rwxrw-r-- 1 peter peter 528 Dec 27 20:05 main.py
-rw-rw-r-- 1 peter peter 528 Dec 27 20:05 main.py EXAMPLE 2 peter@peter-linux:~/PycharmProjects/training$ chmod 754 main.py -rwxr-xr-- 1 peter peter 528 Dec 27 20:05 main.py
-rw-rw-r-- 1 peter peter 528 Dec 27 20:05 main.py EXAMPLE 3 peter@peter-linux:~/PycharmProjects/training$ chmod 777 main.py -rwxrwxrwx 1 peter peter 528 Dec 27 20:05 main.py