Useful for changing permissions on Linux! How to count up to 31 with one hand.

What to do this time

I will explain how to count up to 31 with one hand using binary numbers. Please remember it as it will help you change file permissions on Linux.

What is a binary number?

A binary number is a number whose digits are incremented by 2. What we usually use is a decimal number because it is carried by 10. Since it is a very difficult explanation for me, I have prepared a correspondence table between binary numbers and decimal numbers below. In binary, the number of digits increases when the number becomes 2. Similarly, the number of digits increases when the decimal number becomes 10.

Binary number Decimal number
0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
1001 9
1010 10

How to count binary numbers with your finger

First, put your fist in a goo state. Then all your fingers will be folded. From this state, count the binary numbers as follows. Folded fingers = 0 Standing finger = 1

In this state, it is 0 in decimal, so it is 0 in decimal. 0

1 in decimal, 1 in decimal 0

10 in decimal, 2 in decimal 0

11 in decimal, 3 in decimal 0

100 in decimal, 4 in decimal (not f ◯ ck) 0

101 in decimal, 5 in decimal 0

110 in decimal, 6 in decimal 0

111 in decimal, 7 in decimal 0

You can count up to 2 to the nth power-1 (n is the number of fingers), so if you use the fingers of both hands, you can count up to 1023 with 2 to the 10th power-1. (It's not practical at all ...)

How to read permissions

I prepared a test file on the linux server. There is a description -rwxr--r-- at the left end of the execution result of the ls command. This represents permissions and has the following implications: r = reference authority w = File edit permission x = execute permission for the file

2nd to 4th columns of permissions = What the root user can do 5th to 7th lines of permissions = What the owner of the file can do 8th to 10th lines of permission = What users who belong to the specified group can do

That is, in the example below Root user can be referenced, edited, and executed. In other words, you can do anything. You can only refer to the owner of the file Only users who belong to the group can refer to It means that.

# ls -l
-rwxr--r--.1 yoshida users 0 May 6 03:35 test.txt

Practice

Now let's change the permissions. This time I would like to give the owner of the file edit permission. In conclusion, you can change the permissions with the following command. The important part here is "764". This represents permissions. The first digit, 7 is 111 in binary, so you can give the root user rwx privileges. (That is, no change) The second digit, 6 is 110 in binary, so you can give the owner rw privileges. The second digit, 4 is 100 in binary, so you can give the owner r privileges. (That is, no change)

# chmod 764 test.txt
# ls -l
-rwxrw-r--.1 yoshida users 0 May 6 03:35 test.txt

The flow in my head is shown below.

  1. Edit the 5th to 7th digits because the permission of the file owner is changed.
  2. Since edit authority is given, change from "r--" to "rw-"
  3. "rw-" means 110 in decimal (move your finger here to count how many 110 is in decimal) 4.2 The decimal number 110 is 6! Therefore, it is possible to give the owner edit permission with "chmod 764".

At the end

That is all for this article. It's easy to do, so try it on AWS EC2, or try launching a Linux server by referring to the article I wrote earlier! ·reference I made a virtual server with VMware vSphere I installed CentOS on a virtual machine

Recommended Posts

Useful for changing permissions on Linux! How to count up to 31 with one hand.
How to set up Ubuntu for Windows Subsystem for Linux 2 (WSL2)
[For beginners] How to use for statements on Linux (variables, etc.)
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
How to install nkf with rpm file on Red Hat Enterprise Linux 7.7 (for non-internet environment)
How to install VMware-Tools on Linux
How to get all traffic through VPN with OpenVPN on Linux
How to install aws-session-manager-plugin on Manajro Linux
How to update php on Amazon linux 2
How to display emoji on Manjaro Linux
How to install packages on Alpine Linux
How to install Anisble on Amazon Linux 2
How to install Windows Subsystem For Linux
How to power off Linux with Ultra96-V2
How to update security on CentOS Linux 8
How to install php7.4 on Linux (Ubuntu)
How to find large files on Linux
How to get started with laravel (Linux)
How to prepare an environment with different python version and package for each project with pyenv-virtualenv on Amazon Linux
How to replace with Pandas DataFrame, which is useful for data analysis (easy)
[linux] How to quit without waiting for the other party to disconnect with telnet
Checklist on how to avoid turning the elements of numpy's array with for
How to speed up Pandas apply method with just one sentence (with verification calculation)
Strategy on how to monetize with Python Java
Set up golang with goenv on GNU / Linux
How to install OpenGM on OSX with macports
How to create a shortcut command for LINUX
How to install Camunda Modeler on Manjaro Linux
How to build Java environment on Ubuntu (Linux)
Back up from QNAP to Linux with rsync
How to make Linux compatible with Japanese keyboard
How to pass args or environment variables with Makefile and make command on #Linux
How to use C216 Audio Controller on Arch Linux
How to do zero-padding in one line with OpenCV
Yum command to access MySQL with Python 3 on Linux
How to install Linux on a 32bit UEFI PC
How to install caffe on OS X with macports
Set up Docker on Oracle Linux (7.x) with Vagrant
How to allow nologin users to log in on Linux
How to create a local repository for Linux OS
Autoencoder with Chainer (Notes on how to use + trainer)
[AWS EC2] How to install Maven on Amazon Linux 2
How to install git on Linux such as EC2
[Tips] How to use iPhone as webcam on Linux
How to build a Python environment on amazon linux 2
How to operate Firefox with selenium on Windows Memo
[AWS] How to expand disk space on Amazon linux
How to deal with the problem that pandas 1.1.0 or later build fails on Alpine Linux
How to register the same data multiple times with one input on the Django management screen
[Cyberduck] How to exchange files on Linux (CentOS7) started by VirtualBox with mac using GUI
How to solve the problem that video content cannot be played on Firefox for Linux
"How to count Fukashigi"
How to embed multiple embeds in one message with Discord.py
A memo on how to easily prepare a Linux exercise environment
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
Try to display various information useful for debugging with python
How to check ORM behavior in one file with django
[Ev3dev] How to display bmp image on LCD with python
[Linux] How to deal with garbled characters when viewing files
For beginners, how to deal with common errors in keras
How to create an ISO file (CD image) on Linux