{"id":31225,"date":"2022-09-12T19:57:24","date_gmt":"2022-09-12T19:57:24","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31225"},"modified":"2022-12-23T05:47:25","modified_gmt":"2022-12-23T05:47:25","slug":"linux-tutorials-chmod-commands","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/linux-tutorials-chmod-commands\/","title":{"rendered":"Linux Tutorials: Chmod Commands"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions and the special mode flags of file system objects. Collectively these were originally called its modes, and the name chmod was chosen as an abbreviation of change mode<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"470\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-1.jpg\" alt=\"Annotated ls -l output labeling file type, user, group and other permissions, owner, size and date\" class=\"wp-image-31226\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-1.jpg 596w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-1-300x237.jpg 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"346\" height=\"305\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-2.png\" alt=\"Chmod octal table mapping 0 to 7 to rwx binary values, with chmod 777 giving rwx to owner, group, others\" class=\"wp-image-31227\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-2.png 346w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-2-300x264.png 300w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"505\" height=\"301\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-4.png\" alt=\"Table of chmod numeric values r=4, w=2, x=1 for owner, group and others\" class=\"wp-image-31228\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-4.png 505w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-4-300x179.png 300w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"968\" height=\"722\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-5.jpg\" alt=\"Diagram of chmod 700 temp.txt giving owner rwx and group and others no permissions\" class=\"wp-image-31229\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-5.jpg 968w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-5-300x224.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-5-768x573.jpg 768w\" sizes=\"auto, (max-width: 968px) 100vw, 968px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"149\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-6.jpg\" alt=\"Permission string -rwxr-xr-x split into file type, owner, group and other permissions\" class=\"wp-image-31230\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-6.jpg 462w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/09\/chmod-linux-example-6-300x97.jpg 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">1. Add single permission to a file\/directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod u+x filename<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Add multiple permission to a file\/directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use comma to separate the multiple permission sets as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod u+r,g+x filename<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Remove permission from a file\/directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Following example removes read and write permission for the user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod u-rx filename<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Change permission for all roles on a file\/directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Following example assigns execute privilege to user, group and others (basically anybody can execute this file).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod a+x filename<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Make permission for a file same as another file (using reference)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2\u2019s permission will be set exactly same as file1\u2019s permission.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod --reference=file1 file2<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. Apply the permission to all the files under a directory recursively<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use option -R to change the permission recursively as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod -R 755 directory-name\/<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. Change execute permission only on the directories (files are not affected)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod u+X *<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions and the special mode flags of file system&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4957],"tags":[26308],"class_list":["post-31225","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux-file-permissions"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=31225"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31225\/revisions"}],"predecessor-version":[{"id":31231,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31225\/revisions\/31231"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}