{"id":2124,"date":"2023-12-16T22:32:30","date_gmt":"2023-12-16T22:32:30","guid":{"rendered":"https:\/\/linuxdigest.com\/?p=2124"},"modified":"2023-12-16T23:37:14","modified_gmt":"2023-12-16T23:37:14","slug":"chmod-recursion","status":"publish","type":"post","link":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/","title":{"rendered":"What Does chmod -R Do?"},"content":{"rendered":"\n<p>When you first start using Linux or any other Unix-like system, the commands and the various parameters can become confusing. Searching for information can be even more confusing when you have to wade through a detailed technical manual just to get the meaning of one single character option.<\/p>\n\n\n\n<p>This is why I have been writing some short articles that explain one option at a time, like the <strong>-R<\/strong> option in chmod. I sincerely hope it helps someone get the information they need.<\/p>\n\n\n\n<p>The simple answer is that chmod <strong>-R<\/strong> asks chmod to <strong>recursively change all directories and files <\/strong>below. On most systems only upper case -R is used. Lower case -r does nothing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is chmod?<\/h2>\n\n\n\n<p>Before diving into the <strong><code>-<\/code>R<\/strong> option, it&#8217;s essential to grasp the basics of <strong>chmod<\/strong>. Chmod stands for Change Mode. This command is used to set or modify the access permissions of files and directories. Permissions dictate who can read, write, or execute a file. Knowing how to use <code>chmod<\/code> effectively ensures that your files are accessible to the right users while being protected from unauthorized access.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Does -R Stand for?<\/h2>\n\n\n\n<p>The <strong>&#8211;<\/strong>R option in <code>chmod<\/code> stands for &#8220;recursive&#8221;. When applied, <strong>chmod -R<\/strong> changes the permissions of the specified directory and all its subdirectories and files. This is particularly useful when you want to apply the same permission settings to an entire directory tree. However, it&#8217;s a powerful tool that should be used with caution to avoid unintentionally changing the permissions of critical files.<\/p>\n\n\n\n<p><strong>Practical Usage of chmod -R<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Setting Permissions<\/strong>: To set permissions recursively, you can combine <strong>chmod -R<\/strong> with symbolic or numeric permission values. For instance, <strong>chmod -R 755 directoryName<\/strong> will set the read, write, and execute permissions for the owner and read and execute permissions for the group and others for the directory and all its contents.<\/li>\n\n\n\n<li><strong>Caution and Best Practices<\/strong>: Always double-check the directory path and permissions you&#8217;re setting. A small mistake with <strong>chmod -R<\/strong> can lead to significant security issues or data loss. It&#8217;s recommended to test the command on a small, non-critical directory first. If you set the same permission on every file and subdirectory in a large directory like the \/usr\/ directory, you would definitely cause problems or security issues in your system.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Simple Example of chmod -r<\/h2>\n\n\n\n<p>Take this directory below as an example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"466\" src=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree.jpg\" alt=\"Image showing a directory tree\" class=\"wp-image-2130\" srcset=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree.jpg 900w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree-300x155.jpg 300w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree-768x398.jpg 768w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree-585x303.jpg 585w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<p>As you can see from the image the &#8220;others&#8221; group has no permissions on the files or subdirectories. In stead of changing all the the files one by one, you can change all of them with a single command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod -R o+rw example\/<\/pre>\n\n\n\n<p>You can see from the next image that the read and write permissions have been added to every file and subdirectory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"466\" src=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree2.jpg\" alt=\"\" class=\"wp-image-2131\" srcset=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree2.jpg 900w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree2-300x155.jpg 300w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree2-768x398.jpg 768w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree2-585x303.jpg 585w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Copy Permissions Between Groups of Users<\/h2>\n\n\n\n<p>In some cases it might not be practical to set the permissions the same for every type of file or directory. Say you want to enable the &#8220;others&#8221; group to read and write files and also execute those that are executable. One way to do this is to copy the permissions from the user or the users group to the others group.<\/p>\n\n\n\n<p>This command would accomplish that by copying the group permissions for every file to the others field:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod -R o=g example\/<\/pre>\n\n\n\n<p>This way the file example\/subdir1\/script1.sh is also executable for others.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"466\" src=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree3.jpg\" alt=\"Directory tree showing permissions after copying permissions between groups.\" class=\"wp-image-2132\" srcset=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree3.jpg 900w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree3-300x155.jpg 300w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree3-768x398.jpg 768w, https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/permission_tree3-585x303.jpg 585w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<p><strong>Common Scenarios and Troubleshooting<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>Adjusting Project Permissions<\/strong>: Often, you&#8217;ll need to set consistent permissions for all files in a project. <code>chmod -<\/code>R simplifies this process.<\/li>\n\n\n\n<li><strong>Troubleshooting Permission Issues<\/strong>: If you encounter permission-related errors, carefully review the permissions of your directories and files. Remember, <code>chmod -r<\/code> affects everything within the directory tree, so use it judiciously.<\/li>\n<\/ul>\n\n\n\n<p>If you made it this far, you should have a thourough understanding of the recursion option in chmod. I hope this article helped you solve whatever problem you were trying to solve. I you want to explore more about chmod, I have a couple more articles about it, explaining different situations like <a href=\"https:\/\/linuxdigest.com\/howto\/rw-r-r-step-by-step-explanation\/\">\u201c-rw-r\u2013r\u2013\u201c: Step by Step Explanation<\/a> or <a href=\"https:\/\/linuxdigest.com\/howto\/drxrwxrwt-meaning\/\">drwxrwxrwT: The meaning of the \u201cT\u201d at the end.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you first start using Linux or any other Unix-like system, the commands and the various&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2133,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[27],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What Does chmod -R Do? - Linux Digest<\/title>\n<meta name=\"description\" content=\"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Does chmod -R Do? - Linux Digest\" \/>\n<meta property=\"og:description\" content=\"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Digest\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-16T22:32:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-16T23:37:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/recursion.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1250\" \/>\n\t<meta property=\"og:image:height\" content=\"732\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"The Linux Digest Guy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"The Linux Digest Guy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\"},\"author\":{\"name\":\"The Linux Digest Guy\",\"@id\":\"https:\/\/linuxdigest.com\/#\/schema\/person\/29c97230aa94affab929a88c6a10adb2\"},\"headline\":\"What Does chmod -R Do?\",\"datePublished\":\"2023-12-16T22:32:30+00:00\",\"dateModified\":\"2023-12-16T23:37:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\"},\"wordCount\":668,\"publisher\":{\"@id\":\"https:\/\/linuxdigest.com\/#organization\"},\"articleSection\":[\"Command line tools\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\",\"url\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\",\"name\":\"What Does chmod -R Do? - Linux Digest\",\"isPartOf\":{\"@id\":\"https:\/\/linuxdigest.com\/#website\"},\"datePublished\":\"2023-12-16T22:32:30+00:00\",\"dateModified\":\"2023-12-16T23:37:14+00:00\",\"description\":\"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.\",\"breadcrumb\":{\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/linuxdigest.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Does chmod -R Do?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/linuxdigest.com\/#website\",\"url\":\"https:\/\/linuxdigest.com\/\",\"name\":\"Linux Digest\",\"description\":\"Linux tutorials for everyone\",\"publisher\":{\"@id\":\"https:\/\/linuxdigest.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/linuxdigest.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/linuxdigest.com\/#organization\",\"name\":\"Linux Digest\",\"url\":\"https:\/\/linuxdigest.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/linuxdigest.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2019\/11\/logo1.png\",\"contentUrl\":\"https:\/\/linuxdigest.com\/wp-content\/uploads\/2019\/11\/logo1.png\",\"width\":1102,\"height\":170,\"caption\":\"Linux Digest\"},\"image\":{\"@id\":\"https:\/\/linuxdigest.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/linuxdigest.com\/#\/schema\/person\/29c97230aa94affab929a88c6a10adb2\",\"name\":\"The Linux Digest Guy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/linuxdigest.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ac6bcf745dec6961360ccf2d2711f26c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ac6bcf745dec6961360ccf2d2711f26c?s=96&d=mm&r=g\",\"caption\":\"The Linux Digest Guy\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Does chmod -R Do? - Linux Digest","description":"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/","og_locale":"en_US","og_type":"article","og_title":"What Does chmod -R Do? - Linux Digest","og_description":"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.","og_url":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/","og_site_name":"Linux Digest","article_published_time":"2023-12-16T22:32:30+00:00","article_modified_time":"2023-12-16T23:37:14+00:00","og_image":[{"width":1250,"height":732,"url":"https:\/\/linuxdigest.com\/wp-content\/uploads\/2023\/12\/recursion.jpg","type":"image\/jpeg"}],"author":"The Linux Digest Guy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"The Linux Digest Guy","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#article","isPartOf":{"@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/"},"author":{"name":"The Linux Digest Guy","@id":"https:\/\/linuxdigest.com\/#\/schema\/person\/29c97230aa94affab929a88c6a10adb2"},"headline":"What Does chmod -R Do?","datePublished":"2023-12-16T22:32:30+00:00","dateModified":"2023-12-16T23:37:14+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/"},"wordCount":668,"publisher":{"@id":"https:\/\/linuxdigest.com\/#organization"},"articleSection":["Command line tools"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/","url":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/","name":"What Does chmod -R Do? - Linux Digest","isPartOf":{"@id":"https:\/\/linuxdigest.com\/#website"},"datePublished":"2023-12-16T22:32:30+00:00","dateModified":"2023-12-16T23:37:14+00:00","description":"If you want to set permissions recursively in an entire directory, the -R option for chmod is the simplest way. See example usage of chmod -R here.","breadcrumb":{"@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxdigest.com\/howto\/chmod-recursion\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/linuxdigest.com\/howto\/chmod-recursion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxdigest.com\/"},{"@type":"ListItem","position":2,"name":"What Does chmod -R Do?"}]},{"@type":"WebSite","@id":"https:\/\/linuxdigest.com\/#website","url":"https:\/\/linuxdigest.com\/","name":"Linux Digest","description":"Linux tutorials for everyone","publisher":{"@id":"https:\/\/linuxdigest.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxdigest.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxdigest.com\/#organization","name":"Linux Digest","url":"https:\/\/linuxdigest.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxdigest.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxdigest.com\/wp-content\/uploads\/2019\/11\/logo1.png","contentUrl":"https:\/\/linuxdigest.com\/wp-content\/uploads\/2019\/11\/logo1.png","width":1102,"height":170,"caption":"Linux Digest"},"image":{"@id":"https:\/\/linuxdigest.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxdigest.com\/#\/schema\/person\/29c97230aa94affab929a88c6a10adb2","name":"The Linux Digest Guy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxdigest.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ac6bcf745dec6961360ccf2d2711f26c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ac6bcf745dec6961360ccf2d2711f26c?s=96&d=mm&r=g","caption":"The Linux Digest Guy"}}]}},"_links":{"self":[{"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/posts\/2124"}],"collection":[{"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/comments?post=2124"}],"version-history":[{"count":5,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/posts\/2124\/revisions"}],"predecessor-version":[{"id":2140,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/posts\/2124\/revisions\/2140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/media\/2133"}],"wp:attachment":[{"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/media?parent=2124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/categories?post=2124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxdigest.com\/wp-json\/wp\/v2\/tags?post=2124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}