Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

Access permissions in Linux

YASH PAL, 3 June 202328 May 2024

Every File or directory in Linux has access permissions. There are three types of permissions

  • read
  • write
  • execute

Permissions are defined for three types of users:

  • the owner of the file
  • the group that the owner belongs to.
  • other users

Thus, Linux access permissions are nine bits of information (3 types x 3 types of users), and each of them may have just one of two values: allowed or denied

File Permission

These three types of permission mean slightly different things for files than for directories For files, these permissions grant these rights

  • read Allowed to read the contents of the file
  • write Allowed to modify or delete the file.
  • execute Allowed to run the file as a process, if possible

Viewing File Permissions

The ls command is used to list files and the content of directories. The -l parameter displays permissions. For example, to see the permissions of a file named foo in the file directory/user/bin/bar, you would execute:

ls – l/user/bin/bar/foo

And the command would return something like this:

-rwxr – xr– 1 jsmith guest 3072 June 10 10:25/user/bin/foo

In the example, jsmith is the account that owns foo, and guest is the name of the group that owns/user/bin/foo

The -rwxr – xr– at the left indicates the permissions. The first character the- indicates that/user/bin/foo is a file, not a directory. The rwx shows the permissions for the user class of accounts — in this case, jsmith. The r indicates read permissions, the w writes permissions, and the x executes permission. The following three characters, r-x, show permissions for the group class of accounts, which is guest in this example. Finally, the last three characters, r – -, display permissions for the other class – – any account that is not jsmith and is not in the guest group.

  • r– Read, write and execute permissions for all other users.
  • rw- Read, write and execute permissions for members of the group owning the file
  • rwx Read, write and execute permissions for the other owner of the file.
  • – File type. “-” indicates a regular file. A”d”indicates a directory.

Directory Permissions

While you are logged in on a character-based interface to a Linux system, you are always associated with a directory. The directory you are associated with is the working directory or current directory. When you first log in, the working directory is your home directory.

For directories, the permissions grant these rights:

  • read Allowed to list the contents of the directory.
  • write Allowed to create, modify or delete files in the directory.
  • execute Allowed to access a file in the directory if you know the name of the file.

Viewing Directory Permissions: If you want to see the permissions of the /user/bin/bar directory itself, not its contents, then you need to use the -d command line argument for .s. So, you would execute this command.

ls-ld /user/bin/bar

and you would see something like this:

dr-xrwxr-x 3 jsmith guest 4096 June 10 10.25/user/bin/bar

Permission may also be granted in octal codes.

S.No.DescriptionAbbreviationoctal code
1.Read accessr4
2.Write (Change) permissionsw2
3.Execute script of binary executablex1
4.Read and executerx5
5.Read and writerw6
6.Read, write and executerwx7

The use of octal assignments does not add or remove permissions but assigns the permission explicitly.

Computer Science Tutorials Linux computer scienceLinux

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programmingoneonone | WordPress Theme by SuperbThemes
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions