File and Directory Permissions

  • Linux makes use of a basic permissions system to control user access to files and directories.

Commands

ls -la

  • Long list current folder files and permissions

ls -la
    total 136
    drwxr-xr-x 24 user user  4096 set 12 18:48 .
    drwxr-xr-x  3 root root  4096 apr 13  2021 ..
    drwxrwxr-x  8 user user  4096 lug 25 19:36 .atom
    -rw-------  1 user user 13454 set 12 22:15 .bash_history
    -rw-r--r--  1 user user   220 apr 13  2021 .bash_logout
    -rw-r--r--  1 user user  3795 apr 28  2021 .bashrc
    drwx------ 18 user user  4096 apr 12 15:22 .cache
    drwxrwxr-x  2 user user  4096 apr 12 15:46 code
    drwx------ 24 user user  4096 set  6 21:09 .config
    drwxr-xr-x  2 user user  4096 lug 25 19:37 Desktop
    drwxr-xr-x  7 user user  4096 set 12 18:43 Documents
    [...]
  • The first column displays the permissions, which consist of 10 fields divided into 4 blocks

d rwx r-x r-x

  • 1st character - file type, - for regular file, d for directory, l for symbolic link.

  • 2nd block - owner permissions (user in the 3rd ls -la output column)

  • 3rd block - group permissions (group in the 4th ls -la output column)

  • 4th block - others/world permissions

  • r - read

  • w - write

  • x - execute

    • Execute permission for a directory determines if a user can execute a command in that directory

  • root user can access any file on the filesystem!

๐Ÿ“Œ Understand Linux file permissions.

chmod

  • chmod - change file mode bits

  • Symbolic Mode

  • Numeric octal Mode

Octal number
Permissions
File listing

7 (4+2+1)

read, write and execute

rwx

6 (4+2+0)

read and write

rw-

5 (4+0+1)

read and execute

r-x

4 (4+0+0)

read only

r--

3 (0+2+1)

write and execute

-wx

2 (0+2+0)

write onyl

-w-

1 (0+0+1)

execute only

--x

0 (0+0+0)

none

---

๐Ÿ“Œ Check advanced chmod usage and NetTools calculator or Chmod Calculator.

chown

  • chown - change the owner and group of each file

chgrp

  • chgrp - change the group of each file

  • These commands are useful when extracting files from an archive or making a directory available to all users (like a software in /opt).


Last updated

Was this helpful?