File Permissions using Linux Commands

File Permissions using Linux Commands

We may see that some folders are marked as "read-only" or " view only" and you cannot write or edit them. This is because of file permissions. Some files come with default permissions with security concerns in mind.

There are three types of File permissions -

  • Read (r)
  • Write(w)
  • Execute(x)

Open your Linux system and check out the following commands

image.png

ls -l file.txt to check the permissions allotted to the file

chmod u=rwx,g=rx,o=r file.txt To change the file permission

u stands for user

g stands for group

o stands for others

Alternative, you can use numbers instead of u,g,x --

image.png

  • 4 stands for read
  • 2 stands for write
  • 1 stand for execute
  • 0stands for no permission
  • 7 stands for all the permissions (4+2+1)

sudo chown root file.txt To change the ownership to Root

Root is like the superuser account in UNIX-based system which is used for administrative purposes. It has the highest number of access rights in the system

find . -perm 777 To find all the files,whose permissions are set to 777 means rwx rwx rwx