{"id":3323,"date":"2014-06-24T16:14:29","date_gmt":"2014-06-24T16:14:29","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2014\/06\/24\/chmod-command\/"},"modified":"2023-01-27T16:41:13","modified_gmt":"2023-01-27T21:41:13","slug":"chmod-command","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/","title":{"rendered":"chmod command"},"content":{"rendered":"<p>The <em>chmod<\/em> (short for change mode) command allows you to change permissions on files and folders.<\/p>\n<p><strong>Command: <\/strong>chmod<br \/>\n<strong>Synopsis: <\/strong> chmod [OPTION]&#8230; [MODE]&#8230; FILE&#8230;<br \/>\nchmod [OPTION]&#8230; OCTAL-MODE FILE&#8230;<\/p>\n<div><strong>Options: <\/strong><\/div>\n<table class=\"article_table\">\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Long option name<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>-c<\/td>\n<td>&#8211;changes<\/td>\n<td>Operates like verbose (-v) but report only when a change is made.<\/td>\n<\/tr>\n<tr>\n<td>-f<\/td>\n<td>&#8211;silent, -quiet<\/td>\n<td>Suppress most error messages.<\/td>\n<\/tr>\n<tr>\n<td>-v<\/td>\n<td>&#8211;verbose<\/td>\n<td>Outputs a diagnostic for every file processed.<\/td>\n<\/tr>\n<tr>\n<td>-R<\/td>\n<td>&#8211;recursive<\/td>\n<td>Change all files and directories recursively.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>User Roles and Permissions for Non-Octal Mode<\/h2>\n<p>When formatting using the non octal mode, you will need to know the different roles, operations and permissions that can be used.<\/p>\n<table class=\"article_table\">\n<tbody>\n<tr>\n<th>Category<\/th>\n<th>Operation<\/th>\n<th>Permission<\/th>\n<\/tr>\n<tr>\n<td>u (user)<\/td>\n<td>+ (adds a permission)<\/td>\n<td>r (read)<\/td>\n<\/tr>\n<tr>\n<td>g (group)<\/td>\n<td>&#8211; (removes a permission)<\/td>\n<td>w (write)<\/td>\n<\/tr>\n<tr>\n<td>o (other)<\/td>\n<td>= (sets permission equal to)<\/td>\n<td>x (execute)<\/td>\n<\/tr>\n<tr>\n<td>a (all)<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Examples using the non-octal mode.<\/h2>\n<p>For the following examples, assume the file test.txt starts out with only &#8216;Read&#8217; permissions (r) for all three groups (user, group, and other). It will appear as the following:<\/p>\n<pre class=\"cli\">   # <span style=\"color: red;\">ls -l test.txt<\/span>   -r--r--r--  1 root    root     29K Jun 17 12:01 test.txt<\/pre>\n<h3>Adding a single permission to a single group<\/h3>\n<p><strong>chmod [MODE]&#8230; FILE&#8230;<\/strong> &#8211; This example uses no options, but demonstrates how to add a &#8216;Write&#8217; permission (w) to the &#8216;User&#8217; profile (u) on a file named test.txt. Note that the permissions bracket is now -r<span style=\"color: red;\">w<\/span>-r&#8211;r&#8211;. You can do this for each permission (r,w,x) and for each user type (u,g,o)<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod u+w test.txt<\/span> # <span style=\"color: red;\">ls -l<\/span> -rw-r--r-- 1 root root 29K Jun 17 12:01 test.txt<\/pre>\n<h3>Adding a single permission to All groups<\/h3>\n<p><strong>chmod [MODE]&#8230; FILE&#8230;<\/strong> &#8211; Again, no options are used in this example. Assuming the default permissions (read only) from above, we will add &#8216;Write&#8217; permissions to all three groups at once. Note we use &#8216;a&#8217; instead of a single group (u,g,o). When we list (ls) the file, you can see that &#8216;w&#8217; was added to all three group profiles.<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod a+w test.txt<\/span> # <span style=\"color: red;\">ls -l<\/span> -rw-rw-rw- 1 root root 29K Jun 17 12:01 test.txt<\/pre>\n<h3>Adding multiple permissions at once.<\/h3>\n<p><strong>chmod [MODE]&#8230; FILE&#8230;<\/strong> &#8211; Moving ahead with the base command, this example demonstrates how to add multiple permissions with a single command. In this case, we will add a &#8216;Write&#8217; (w) permission to the &#8216;User&#8217; (u) group and the &#8216;Execute&#8217; (x) permission to the &#8216;Owner&#8217; (o) group. After listing (ls) the file, you can see the User portion of the permissions are set to &#8216;rw-&#8216; and the Group section is set to &#8216;r-x&#8217; while the Other section remained the same with &#8216;r&#8211;&#8216;.<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod u+w,g+x test.txt<\/span> # <span style=\"color: red;\">ls -l test.txt<\/span> -rw-r-xr-- 1 root root 29433 Jun 17 12:01 test.txt<\/pre>\n<h3>Using the Verbose Option.<\/h3>\n<p><strong>chmod [OPTION]&#8230; [MODE]&#8230; FILE&#8230;<\/strong> &#8211; This example is the same eample as above, but this time we added the Verbose (-v) option. This displays the changes that were made as the command is run. As you can see, we do not have to use the &#8216;<em>ls<\/em>&#8216; command afterwards in order to see how the permissions ended up.<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod -v u+w,g+x test.txt<\/span> mode of `test.txt' changed to 0654 (rw-r-xr--)<\/pre>\n<h2>Examples using the Octal mode.<\/h2>\n<p>For the following examples, assume the file test.txt starts out with only &#8216;Read&#8217; permissions (r) for all three groups (user, group, and other). IN Octal mode, these are represented as 444.<\/p>\n<pre class=\"cli\">   # <span style=\"color: red;\">ls -l test.txt<\/span>   -r--r--r--  1 root    root     29K Jun 17 12:01 test.txt<\/pre>\n<h3>Changing permissions for a single file<\/h3>\n<p><strong>chmod OCTAL-MODE FILE&#8230;<\/strong> &#8211; Here we use the base command without any options. Assuming 444 (r&#8211;r&#8211;r&#8211;) permissions on the test.txt file, we change it to 755 (rwx-r-x-r-x).<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod 755 test.txt<\/span> # <span style=\"color: red;\">ls -l test.txt<\/span> -rwxr-xr-x 1 root root 29433 Jun 17 12:01 test2.txt<\/pre>\n<h3>Changing permissions on a directory<\/h3>\n<p><strong>chmod OCTAL-MODE [DIR]&#8230;<\/strong> &#8211; This example shows how us changing the permissions on a directory named <em>php<\/em>.<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod 755 php<\/span> mode of `php' changed to 0777 (rwxrwxrwx) # <span style=\"color: red;\">ls -l<\/span> drwxrwxrwx  3 root root 4.0K Jun 15 09:08 php\/<\/pre>\n<h3>Changing ALL files and folders to the same permissions<\/h3>\n<p><strong>chmod [OPTION]&#8230; OCTAL-MODE [DIR]&#8230;<\/strong> &#8211; Here we demonstrate how to change all files and folders within a specific folder to the same permissions. By doing this recursively (-R), it will continue to go to all subdirectories and change all files and folders there as well, until there are no more to change.<\/p>\n<pre class=\"cli\"> # <span style=\"color: red;\">chmod -R 755 php<\/span> mode of `php' changed to 0777 (rwxrwxrwx) # <span style=\"color: red;\">ls -l<\/span> drwxrwxrwx  3 root root 4.0K Jun 15 09:08 subfolder\/ -rwxrwxrwx  3 root root 5.0K Jun 15 09:08 test1.txt -rwxrwxrwx  3 root root 2.0K Jun 15 09:08 test2.txt -rwxrwxrwx  3 root root 9.0K Jun 15 09:08 test3.txt -rwxrwxrwx  3 root root 7.0K Jun 15 09:08 test4.txt<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The chmod (short for change mode) command allows you to change permissions on files and folders. Command: chmod Synopsis: chmod [OPTION]&#8230; [MODE]&#8230; FILE&#8230; chmod [OPTION]&#8230; OCTAL-MODE FILE&#8230; Options: Option Long option name Description -c &#8211;changes Operates like verbose (-v) but report only when a change is made. -f &#8211;silent, -quiet Suppress most error messages. -v<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\"> Read More ><\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4308],"tags":[],"class_list":["post-3323","post","type-post","status-publish","format-standard","hentry","category-linux"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>chmod command | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Learn how to use the Linux chmod command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"chmod command | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Learn how to use the Linux chmod command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-24T16:14:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-27T21:41:13+00:00\" \/>\n<meta name=\"author\" content=\"Scott Mitchell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Scott Mitchell\" \/>\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:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\"},\"author\":{\"name\":\"Scott Mitchell\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\"},\"headline\":\"chmod command\",\"datePublished\":\"2014-06-24T16:14:29+00:00\",\"dateModified\":\"2023-01-27T21:41:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\"},\"wordCount\":595,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\",\"name\":\"chmod command | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2014-06-24T16:14:29+00:00\",\"dateModified\":\"2023-01-27T21:41:13+00:00\",\"description\":\"Learn how to use the Linux chmod command.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"chmod command\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\",\"name\":\"Scott Mitchell\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"chmod command | InMotion Hosting","description":"Learn how to use the Linux chmod command.","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:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/","og_locale":"en_US","og_type":"article","og_title":"chmod command | InMotion Hosting","og_description":"Learn how to use the Linux chmod command.","og_url":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2014-06-24T16:14:29+00:00","article_modified_time":"2023-01-27T21:41:13+00:00","author":"Scott Mitchell","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Scott Mitchell","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/"},"author":{"name":"Scott Mitchell","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed"},"headline":"chmod command","datePublished":"2014-06-24T16:14:29+00:00","dateModified":"2023-01-27T21:41:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/"},"wordCount":595,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/","url":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/","name":"chmod command | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2014-06-24T16:14:29+00:00","dateModified":"2023-01-27T21:41:13+00:00","description":"Learn how to use the Linux chmod command.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/chmod-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"chmod command"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed","name":"Scott Mitchell","url":"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":{"id":4308,"name":"Linux","slug":"linux","link":"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/"},"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=3323"}],"version-history":[{"count":1,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3323\/revisions"}],"predecessor-version":[{"id":102697,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3323\/revisions\/102697"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=3323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=3323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=3323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}