• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Linux Insight Blogs: chmod

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,483
Баллы
155

Introduction


Welcome 👋 to this blog. In this blog we will gonna be learning about the chmod a command-line utility on Unix/Linux systems. A command-line utility is a program or tool that you run using CLI(Command Line Interface) instead of GUI(graphical user interface).

chmod


chmod stands for change mode. It's a command-line utility which used to change the permissions of files and directories. In Unix/Linux or in general computer Science we can define permission following:


  • read(r), view file content


  • write(w), modify file content


  • execute(x), run as a program

With the help of this command, we can change the permissions of the files assigned to three user groups.

In Unix/Linux systems we have three user classes:


  • Owner(u), user who owns a file


  • group(g), users in the file group


  • other(o), other users
Let's get our hand dirty with code


Open your terminal by pressing CTRL + Alt + T.

We have 2 ways to use this commands

1. With symbols


In this we will be using these symbols +, - and = symbols to modify the permissions. The meaning of the symbols + (Add permission), - (Remove permission) and = (set exact permissioin).

Let's start typing the command in the terminal:

I have created a three files in the blog folder.


ankur@ankur:~/Desktop/blog$ ls
file1.txt file2.txt file3.txt




Let's check the permission of all the files by executing the ls commands with -l flag.


ankur@ankur:~/Desktop/blog$ ls -l
total 0
-rw-rw-r-- 1 ankur ankur 0 Jun 28 23:15 file1.txt
-rw-rw-r-- 1 ankur ankur 0 Jun 28 23:15 file2.txt
-rw-rw-r-- 1 ankur ankur 0 Jun 28 23:15 file3.txt




The -rw-rw-r-- part, which represents file permissions in Linux. This string has 10 characters, structured like this:


[Type][Owner][Group][Others]
- rw- rw- r--



  • Give execute permission to the owner

ankur@ankur:~/Desktop/blog$ chmod u+x file1.txt
ankur@ankur:~/Desktop/blog$ ls -l
total 0
-rwxrw-r-- 1 ankur ankur 0 Jun 28 23:15 file1.txt




Now you can see the x in the owner string, which means it has execute privilege.

  • Removing execute permission from the owner

ankur@ankur:~/Desktop/blog$ chmod u-x file1.txt
ankur@ankur:~/Desktop/blog$ ls -l
total 0
-rw-rw-r-- 1 ankur ankur 0 Jun 28 23:15 file1.txt




Now you can see the x vanishes in the owner string.

  • Set exact permission explicitily

ankur@ankur:~/Desktop/blog$ chmod u=rwx,g=r,o=wr file1.txt
ankur@ankur:~/Desktop/blog$ ls -l
total 0
-rwxr--rw- 1 ankur ankur 0 Jun 28 23:15 file1.txt




You can see the string is changed.

2. With Numbers


Each permission is mapped to a numeric value.


r (read) 4
w (write) 2
x (execute) 1




So, everything worked the same expect in this method we passed the 3 string 1st one for owner, 2nd one for group and the 3rd one for others

for example


ankur@ankur:~/Desktop/blog$ chmod 755 file1.txt
ankur@ankur:~/Desktop/blog$ ls -l
total 0
-rwxr-xr-x 1 ankur ankur 0 Jun 28 23:15 file1.txt




755 will be breaked into(7, 5, 5)
7 -> 4+2+1 (rwx)
5 -> 4+1 (r-x)
5 -> 4+1 (r-x)




You can visit

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

to see the mapping of permission with the numeric.

🎉 You nailed it


You’ve now learned how to use the chmod command to change the permission of the files with two methods symbolic and numerical. It’s time to open your terminal and try these commands on your own system. Play around, explore, and see what's happening under the hood of your machine. Got something cool or unexpected? Share your best use case of chmod commands in the comment section.

Let's connect
📧 Email:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.


🔗 LinkedIn:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.


🔗 Twitter:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.





Источник:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу