{"id":20152,"date":"2023-07-31T09:23:14","date_gmt":"2023-07-31T09:23:14","guid":{"rendered":"https:\/\/linuxways.net\/?p=20152"},"modified":"2023-07-31T09:23:14","modified_gmt":"2023-07-31T09:23:14","slug":"how-to-recursively-change-file-permissions-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-recursively-change-file-permissions-in-linux\/","title":{"rendered":"How to Recursively Change File Permissions in Linux"},"content":{"rendered":"<p>There will surely be a time when you will try to access and open a file or a directory but you could not. You will get a permission denied message from your terminal. This is because of the permissions that refrain us to open or access that file.<\/p>\n<p>In Linux, permissions are a very important aspect of system security. These permissions are read, write and execute.<\/p>\n<p>This article will discuss and explain these permissions in detail.<\/p>\n<h2><strong>chmod command and its syntax<\/strong><\/h2>\n<p>chmod is a command that we use to set up the permissions for our files and folders. It has a syntax that we need to follow.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">chmod<\/span> <span class=\"br0\">&#91;<\/span>options<span class=\"br0\">&#93;<\/span> <span class=\"br0\">&#91;<\/span>permissions<span class=\"br0\">&#93;<\/span> <span class=\"br0\">&#91;<\/span><span class=\"kw2\">file<\/span> or directory<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>There are some options that we use along with the chmod command and these are as follows.<\/p>\n<ul>\n<li>R: Used forRecursively changing the permissions of files and directories<\/li>\n<li>-v: Used to output a message.<\/li>\n<li>-c: It gets used to output a message only for files that have changed.<\/li>\n<\/ul>\n<p>We have three types of users. The first one is the owner who creates the file of the directory in Linux. The second one is the group of which the user is part. The last one is the other type of users who either are owners or the part of any group<\/p>\n<p>Now let&#8217;s have an example.<\/p>\n<p>Let&#8217;s take an example as we have a file on our desktop and we need to assign all permissions to all the users. We have three types of users in Linux distributions \u201cusers\u201d, \u201cgroups\u201d, and \u201cother\u201d types of users.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">chmod<\/span> <span class=\"re5\">-R<\/span> <span class=\"nu0\">777<\/span> file.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"556\" class=\"wp-image-20153\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-1.png 749w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-1-300x223.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/p>\n<p>Now, we will use the ls command to verify and make sure if the permissions got changed or not.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> file.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"363\" class=\"wp-image-20154\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-2.png 737w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-2-300x148.png 300w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/p>\n<p>Here it shows that we have successfully changed the permissions for the file.<\/p>\n<h2><strong>How to change permissions recursively with symbolic mode?<\/strong><\/h2>\n<p>This is another way of assigning permissions as it allows us to assign permissions in a more granular way. We can assign different permissions to different users. As we have three kinds of users in our Linux distributions.<\/p>\n<p>Let\u2019s see the syntax.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">chmod<\/span> <span class=\"re5\">-R<\/span> <span class=\"br0\">&#91;<\/span><span class=\"kw2\">who<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#91;<\/span>operator<span class=\"br0\">&#93;<\/span><span class=\"br0\">&#91;<\/span>permissions<span class=\"br0\">&#93;<\/span> <span class=\"br0\">&#91;<\/span>directory<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>Now let&#8217;s take an example here and let\u2019s say, we want to assign all the permission to the owner of the file, read and write permission to the group and only read permission to the other users. For that, we will use the permissions with the chmod command like the following.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">chmod<\/span> <span class=\"re5\">-R<\/span> <span class=\"re2\">u<\/span>=rwx,<span class=\"re2\">g<\/span>=rx,<span class=\"re2\">o<\/span>=x file.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"556\" class=\"wp-image-20155\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-3.png 739w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-20152-3-300x226.png 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/p>\n<p>The below table shows the permission along with the symbols and numbers we can use to assign different permission to our files and folders.<\/p>\n<table>\n<thead>\n<tr>\n<th><strong>Octal Notation<\/strong><\/th>\n<th><strong>BInary<\/strong><\/th>\n<th><strong>Symbolic Representation<\/strong><\/th>\n<th><strong>Permissions<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>0<\/strong><\/th>\n<th><strong>000<\/strong><\/th>\n<th><strong>\u2014<\/strong><\/th>\n<th><strong>No permission<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>1<\/strong><\/th>\n<th><strong>001<\/strong><\/th>\n<th><strong>\u2013x<\/strong><\/th>\n<th><strong>Execute<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>2<\/strong><\/th>\n<th><strong>010<\/strong><\/th>\n<th><strong>-w-<\/strong><\/th>\n<th><strong>Write<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>3<\/strong><\/th>\n<th><strong>011<\/strong><\/th>\n<th><strong>-wx<\/strong><\/th>\n<th><strong>Write and Execute<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>4<\/strong><\/th>\n<th><strong>100<\/strong><\/th>\n<th><strong>r\u2013<\/strong><\/th>\n<th><strong>Read<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>5<\/strong><\/th>\n<th><strong>101<\/strong><\/th>\n<th><strong>r-x<\/strong><\/th>\n<th><strong>Read and Execute<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>6<\/strong><\/th>\n<th><strong>110<\/strong><\/th>\n<th><strong>rw-<\/strong><\/th>\n<th><strong>Read and Write<\/strong><\/th>\n<\/tr>\n<tr>\n<th><strong>7<\/strong><\/th>\n<th><strong>111<\/strong><\/th>\n<th><strong>rwx<\/strong><\/th>\n<th><strong>Read, write, and Execute<\/strong><\/th>\n<\/tr>\n<\/thead>\n<\/table>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Keeping permission on the files allows us to have more security and also helps us to keep the authorizations over the content. This phenomenon is very useful and handy when we have more than one user on one system. Permissions will make sure that only privileged users are allowed to use and see the content of files and folders.<\/p>\n<p>This article was all about how we can use the permission on our files and folders along with different methods that we can use to do that.<\/p>","protected":false},"excerpt":{"rendered":"<p>File permissions allows us to keep the authorization and praivaly of our files in Linux distribution for all kind of users with single command <\/p>","protected":false},"author":110,"featured_media":20156,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-20152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/20152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=20152"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/20152\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/20156"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=20152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=20152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=20152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}