Send by LINE
B! Bookmarks in Hate-bu
Bookmarks in Pocket
RSS feeds

Linux chmod, change file and directory permissions

programing image

The chmod command is used to change the permissions on files and directories.

It also explains how to read file and directory information.

This is written by a Japanese who can't speak English with the help of translation application. Sorry if it's not good.

Commands to change permissions

The chmod command to change file and directory permissions is used in this way.

chmod 777 target

Three numbers, from left to right.

Logged in users


Ohter Users


The values are from 0 to 7 and are shown in the following table.

Table of permination values

valuebinary digitssymbolmeaning
3011-wxwrite, execute
5101r-xread, execute
6110rw-read, write
7111rwxread, write, execute
(all the authority)

For example.

Logged in users: read, write, execute (all)

group: read, execute

Ohter Users: execute

If you want to add this permission to the sample.txt file, do this.

Change the permissions of sample.txt
chmod 751 sample.txt

The non-numeric symbols can also be used, but they are easier to use as they are grouped together and require only three characters.

If you want to change the permissions of a directory, you can use the "-R" option to change the files and directories under it.

Change the "sample" directory and its subdirectories together
chmod -R 751 sample

How to read file and directory information in Linux

I used chmod to specify the permissions as a number 0-7. I only showed the resulting table, but I didn't explain the meaning of it.

The meaning of the numbers is easier to understand if you look at how files and directories are displayed in Linux.

Let's look at it first.

"ls" command will show you the information about the files and directories.

Command to view file and directory information
ls -l
-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Here's the result. I'll explain the details one by one.

File Types

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

The first character is the type of file.

lsymbolic link


-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Next, a nine-character string follows, uninterrupted by the file type.

File access rights.

  • Who did?
  • What can you do?

will be displayed.

Who owns the file?

"Who?" separates 9 characters by 3 characters.

ownergroupUsers other than the owner

The "owner" is the user who created the file and the user belongs to some group.

The last one is a user other than the file creator.

What can a non-ownership user do?

Set this up.

What can the file do?

"What can I do? are these three.

Read from fileWrite to fileRun the file

Specify three permissions, one character for each of the three users.

There are two ways to specify permissions: alphabetic and numerical.

The table summarizes.

Alphabetical designation

The alphabetic symbol is a single letter of the word.

  • read
  • write
  • execute
Numeric designation

The number is expressed as a binary number with three digits.

The order of the numbers looks like this


Each one uses the value of a flag of 1. It's easy to remember this table.

memorized table
Specify multiple permissions numerically

It's readable and executable.

Thus, if you want to give multiple permissions, add them together.

Then all permissions would look like this.

1 + 2 + 4 = 7

As we will see, the values we use are 0-7.

A table of all permission patterns

All permission patterns are summarized in the table.

ValueBinary digitsSymbolPermissions to allow
0000---No authority at all.
3011-wxWrite, Execute
5101r-xRead, Execute
6110rw-Read, Write
7111rwxRead, Write, Execute

Again, these three character permissions are assigned to the owner, group and other users.

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Red: owner

Green: group

Blue: Users other than the owner

Three color-coded permissions can be made.

Permissions error

If you try to operate on a file or directory without permission, an error occurs.

Permission Error Messages
Permission denied

Number of hard links

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Next to the permissions is the number of hard links, separated by a single space.

There's not much point in knowing the details here, so this is about as much as you can remember.

  • file, the value is 1
  • directory, the approximate number of files and directories underneath

In Linux, there are two hard links directly under the directory that count.

.current directory
..The parent (one level up) directory

It's a number of hard links, so symbolic links do not count.

In that sense, it won't be an exact number of files and directories.

Names of owners and groups

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Next to the number of hard links, space out one and show two names.

file owner's name

The name of the group to which the file owner belongs

Leave one space between the owner's name and the group's name.

The owner of the file is the creator of the file

File Size

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Next to the owner's name and group name is the file size, with one space left blank.

The unit is bytes and 0 for a directory.

Update Date

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Next to the file size is the date and time of the file's last modification, with a single space after the file size.

If it's a directory, it's the date and time the file was last modified when the directory configuration changed.

If it is a new file, it is the date and time of its creation.

The name of the file or directory

-rw-rw-r-- 1 xxxxx yyyyy 1875611 Aug 16 23:57 zzzzzz

Lastly, the name of the file or directory, leaving one space blank.


The 'chmod' command has other options than '-R', but you won't use them very often. The rest of the usage is simple, so it's easy to learn.

Just look at the first table I showed you, so you don't have to struggle to remember it.

Leave a Reply