{"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":"
<\/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>\nThis 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>\nHere are some other commands that you can build base on previous<\/p>\n
\nfind . -type f -name '*.htm*' -exec chmod 644 {} \\;\n<\/pre>\nThis 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>\nThis 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