• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Linux File/Directory Permissions cheat sheet

By admin

Here is a short note/cheat sheet for Linux directory and file permissions. The table below gives numbers for all permission types of a File/Directory.

Number          Permission Type             Symbol
  0              No Permission                —
  1              Execute                      –x
  2              Write                        -w-
  3              Execute + Write              -wx
  4              Read                         r–
  5              Read + Execute               r-x
  6              Read + Write                  rw-
  7              Read + Write + Execute        rwx

For example 777 permission to /etc folder means the folder has all the read, write and executable permissions for owner, group and all users.

Owner - The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
Group - The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
All users - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

File and Directory Permissions

Below is sample output from ls -l; you can see from the first character of each line that foo and bar are directories (indicated by the d) and that meta is a regular file (indicated by the -).

$ ls -l
drwxr-xr-x 2 user user    6 Jan  7  2015 Desktop
-rw-rw-r-- 1 user user    0 Feb 16 14:17 file1
-rw-r--r-- 1 user wheel   0 Feb 16 14:22 file2

The next nine characters show the file’s permissions for user, group, and others (or everyone else) as shown below, with parentheses added for clarity:

-(rw-) (r--) (r--) 1 user wheel   0 Feb 16 14:22 file2

Now the owner has read and write permissions (rw-), the group and everyone else has only read permissions (r–). This is called symbolic representation because letters such as r, w, and x, are used to indicate permissions. Permissions can also be represented numerically: r = 4; w = 2; x = 1

Add each section so that the permissions of the file meta (from the example above) would be 664. Here is another way to look at how we come to that number:

-(rw-)  (rw-)  (r--)
-(42-)  (42-)  (4--)
 6       6       4

Adding the numbers in each section results in permissions of 664.

Changing File Permissions

The chmod command is used to alter the permissions of a file. It may be used to add or remove permissions symbolically. For example, to add execute permissions for the owner of a file you would run:

$ chmod u+x file_name

Or, to add read and write permissions for the group that owns the file, you would run:

$ chmod g+rw file_name

Instead of adding permissions, the symbolic syntax of chmod can also be used to subtract or set to some absolute value as shown in these examples:

$ chmod o-w file_name
$ chmod u=rwx,g=rx,o= file_name

The chmod command can also explicitly set permissions using a numerical representation. For example, to set permissions on a file to rwxrwxr–, you would run:

$ chmod 774 file_name

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Configure Multiple Fencing-device Levels in Pacemaker Cluster
  2. How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7
  3. How to Configure Proxy in CentOS/RHEL/Fedora
  4. CentOS / RHEL : How to add a new Physical Volume to an existing Volume Group
  5. How to Tune Btrfs Filesystem for Better Performance
  6. How to Remove virbr0 and lxcbr0 Interfaces on CentOS/RHEL 6,7
  7. CentOS / RHEL : How to rotate /var/log/wtmp and /var/log/btmp file using logrotate
  8. How To Disable Or Extend System Logging Rate-limit on CentOS/RHEL 7
  9. How to add a Custom Script to systemd in CentOS/RHEL 7
  10. CentOS / RHEL : How to find if a network port is open or not?

You May Also Like

Primary Sidebar

Recent Posts

  • What are different Oracle Database Vault Roles
  • Unable to export realm protected table using data pump
  • Beginners Guide to Oracle Database Vault
  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary