{"id":654,"date":"2013-05-27T18:27:13","date_gmt":"2013-05-27T18:27:13","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=654"},"modified":"2013-05-27T18:27:13","modified_gmt":"2013-05-27T18:27:13","slug":"unix-recursively-chmod-only-directories-or-files","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/unix-recursively-chmod-only-directories-or-files\/","title":{"rendered":"Unix – Recursively chmod only directories or files"},"content":{"rendered":"

\"directories\"<\/p>\n

Have you ever come across the problem of needing to chmod many directories and sub-directories, but you don\u2019t want to touch any of the files? Maybe it\u2019s the exact opposite, or you need to recursively change the permissions on only files with a specific extension. If so, this article is for you<\/p>\n

To change permission of all directories to 755, execute this command in terminal<\/p>\n

<\/p>\n

\nfind . -type d -exec chmod 755 {} \\;\n<\/pre>\n

This will \u201cfind\u201d all directories, starting at \u201c.\u201c, and chmod them to\u00a0755.<\/p>\n

The following snippet does the opposite and finds only files. The difference (beside the file permissions) is the \u201c-type f\u201c, \u201cf\u201d specifies files and \u201cd\u201d directories.<\/p>\n

\nfind . -type f -exec chmod 644 {} \\;\n<\/pre>\n
\n
<\/pre>\n

Here are some other commands that you can build base on previous<\/p>\n

\nfind . -type f -name '*.htm*' -exec chmod 644 {} \\;\n<\/pre>\n

This lets you \u201cfind\u201d files (\u201c-type f\u201c) with a specific extension (\u201c-name ‘*.htm*’\u201c) and chmod them with your desired permission (\u201c-exec chmod 644 {}\u201c).<\/p>\n

\nchmod -R o+rX\n<\/pre>\n

This snippet will recursively chmod \u201cother\u201d (\u201co\u201c) permissions with read\/eXecutable (\u201c+rX\u201c), and the capital X ensures that directories and files set (user\/group permissions) to executable will be properly modified, while ignoring regular (non-executable) files.<\/p>\n","protected":false},"excerpt":{"rendered":"

Have you ever come across the problem of needing to chmod many directories and sub-directories, but you don\u2019t want to touch any of the files? Maybe it\u2019s the exact opposite, or you need to recursively change the permissions on only files with a specific extension. If so, this article is for you To change permission…<\/p>\n

Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,53,66],"tags":[48,49,92,51,64],"aioseo_notices":[],"views":5,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/654"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=654"}],"version-history":[{"count":0,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}