[{"data":1,"prerenderedAt":874},["ShallowReactive",2],{"guide-chmod-recursive-permissions":3},{"id":4,"title":5,"body":6,"date":865,"description":866,"extension":867,"meta":868,"navigation":97,"path":869,"readingTime":870,"seo":871,"stem":872,"__hash__":873},"guides\u002Fguides\u002Fchmod-recursive-permissions.md","Setting Recursive Chmod Permissions",{"type":7,"value":8,"toc":842},"minimark",[9,14,27,34,38,41,128,143,148,197,203,207,218,274,284,288,294,312,319,323,374,378,382,396,432,436,439,534,538,541,594,600,604,608,629,640,644,660,694,698,707,735,739,742,791,794,798,821,825,828,838],[10,11,13],"h2",{"id":12},"the-recursive-permission-problem","The Recursive Permission Problem",[15,16,17,18,22,23,26],"p",{},"Running ",[19,20,21],"code",{},"chmod -R 755 \u002Fvar\u002Fwww"," seems straightforward — apply 755 to everything under ",[19,24,25],{},"\u002Fvar\u002Fwww",". But this creates a common problem: 755 makes files executable, which is unnecessary and potentially dangerous for regular files. You usually want directories at 755 (rwxr-xr-x) and files at 644 (rw-r--r--).",[15,28,29,30,33],{},"A single ",[19,31,32],{},"chmod -R"," can't set different permissions for files versus directories. You need more targeted approaches.",[10,35,37],{"id":36},"the-standard-solution-find-chmod","The Standard Solution: Find + Chmod",[15,39,40],{},"The most widely used pattern separates files and directories:",[42,43,48],"pre",{"className":44,"code":45,"language":46,"meta":47,"style":47},"language-bash shiki shiki-themes github-light github-dark","# Directories: 755 (rwxr-xr-x)\nfind \u002Fvar\u002Fwww -type d -exec chmod 755 {} +\n\n# Files: 644 (rw-r--r--)\nfind \u002Fvar\u002Fwww -type f -exec chmod 644 {} +\n","bash","",[19,49,50,59,92,99,105],{"__ignoreMap":47},[51,52,55],"span",{"class":53,"line":54},"line",1,[51,56,58],{"class":57},"sJ8bj","# Directories: 755 (rwxr-xr-x)\n",[51,60,62,66,70,74,77,80,83,86,89],{"class":53,"line":61},2,[51,63,65],{"class":64},"sScJk","find",[51,67,69],{"class":68},"sZZnC"," \u002Fvar\u002Fwww",[51,71,73],{"class":72},"sj4cs"," -type",[51,75,76],{"class":68}," d",[51,78,79],{"class":72}," -exec",[51,81,82],{"class":68}," chmod",[51,84,85],{"class":72}," 755",[51,87,88],{"class":68}," {}",[51,90,91],{"class":68}," +\n",[51,93,95],{"class":53,"line":94},3,[51,96,98],{"emptyLinePlaceholder":97},true,"\n",[51,100,102],{"class":53,"line":101},4,[51,103,104],{"class":57},"# Files: 644 (rw-r--r--)\n",[51,106,108,110,112,114,117,119,121,124,126],{"class":53,"line":107},5,[51,109,65],{"class":64},[51,111,69],{"class":68},[51,113,73],{"class":72},[51,115,116],{"class":68}," f",[51,118,79],{"class":72},[51,120,82],{"class":68},[51,122,123],{"class":72}," 644",[51,125,88],{"class":68},[51,127,91],{"class":68},[15,129,130,131,134,135,138,139,142],{},"The ",[19,132,133],{},"{} +"," syntax batches matched paths into fewer ",[19,136,137],{},"chmod"," calls, making it significantly faster than ",[19,140,141],{},"{} \\;"," for large directory trees.",[144,145,147],"h3",{"id":146},"performance-comparison","Performance Comparison",[149,150,151,167],"table",{},[152,153,154],"thead",{},[155,156,157,161,164],"tr",{},[158,159,160],"th",{},"Command Calls",[158,162,163],{},"10,000 Files",[158,165,166],{},"100,000 Files",[168,169,170,184],"tbody",{},[155,171,172,178,181],{},[173,174,175,177],"td",{},[19,176,141],{}," (one per file)",[173,179,180],{},"~10,000 chmod calls",[173,182,183],{},"~100,000 chmod calls",[155,185,186,191,194],{},[173,187,188,190],{},[19,189,133],{}," (batched)",[173,192,193],{},"~100 chmod calls",[173,195,196],{},"~1,000 chmod calls",[15,198,199,200,202],{},"Use ",[19,201,133],{}," unless you have a specific reason for per-file execution.",[10,204,206],{"id":205},"using-xargs-for-large-trees","Using Xargs for Large Trees",[15,208,209,210,213,214,217],{},"For very large directory trees, ",[19,211,212],{},"xargs"," can be faster than ",[19,215,216],{},"-exec",":",[42,219,221],{"className":44,"code":220,"language":46,"meta":47,"style":47},"find \u002Fvar\u002Fwww -type d -print0 | xargs -0 chmod 755\nfind \u002Fvar\u002Fwww -type f -print0 | xargs -0 chmod 644\n",[19,222,223,251],{"__ignoreMap":47},[51,224,225,227,229,231,233,236,240,243,246,248],{"class":53,"line":54},[51,226,65],{"class":64},[51,228,69],{"class":68},[51,230,73],{"class":72},[51,232,76],{"class":68},[51,234,235],{"class":72}," -print0",[51,237,239],{"class":238},"szBVR"," |",[51,241,242],{"class":64}," xargs",[51,244,245],{"class":72}," -0",[51,247,82],{"class":68},[51,249,250],{"class":72}," 755\n",[51,252,253,255,257,259,261,263,265,267,269,271],{"class":53,"line":61},[51,254,65],{"class":64},[51,256,69],{"class":68},[51,258,73],{"class":72},[51,260,116],{"class":68},[51,262,235],{"class":72},[51,264,239],{"class":238},[51,266,242],{"class":64},[51,268,245],{"class":72},[51,270,82],{"class":68},[51,272,273],{"class":72}," 644\n",[15,275,130,276,279,280,283],{},[19,277,278],{},"-print0"," and ",[19,281,282],{},"-0"," flags handle filenames with spaces or special characters safely. Never omit these flags when dealing with user-uploaded content or uncontrolled filenames.",[10,285,287],{"id":286},"the-chmod-x-trick","The Chmod X Trick",[15,289,130,290,293],{},[19,291,292],{},"X"," (capital X) permission flag sets execute only on directories and files that already have execute permission:",[42,295,297],{"className":44,"code":296,"language":46,"meta":47,"style":47},"chmod -R a+X \u002Fvar\u002Fwww\n",[19,298,299],{"__ignoreMap":47},[51,300,301,303,306,309],{"class":53,"line":54},[51,302,137],{"class":64},[51,304,305],{"class":72}," -R",[51,307,308],{"class":68}," a+X",[51,310,311],{"class":68}," \u002Fvar\u002Fwww\n",[15,313,314,315,318],{},"This is useful when you want to add execute to directories without making all files executable. However, it has a catch: files that already have any execute bit set will keep it. If your files are already 755 by mistake, ",[19,316,317],{},"a+X"," won't fix them — it preserves the existing execute bits.",[144,320,322],{"id":321},"safe-pattern-reset-then-apply","Safe Pattern: Reset Then Apply",[42,324,326],{"className":44,"code":325,"language":46,"meta":47,"style":47},"# First, strip all execute bits\nchmod -R a-x \u002Fvar\u002Fwww\n\n# Then add execute back for directories only\nfind \u002Fvar\u002Fwww -type d -exec chmod a+x {} +\n",[19,327,328,333,344,348,353],{"__ignoreMap":47},[51,329,330],{"class":53,"line":54},[51,331,332],{"class":57},"# First, strip all execute bits\n",[51,334,335,337,339,342],{"class":53,"line":61},[51,336,137],{"class":64},[51,338,305],{"class":72},[51,340,341],{"class":68}," a-x",[51,343,311],{"class":68},[51,345,346],{"class":53,"line":94},[51,347,98],{"emptyLinePlaceholder":97},[51,349,350],{"class":53,"line":101},[51,351,352],{"class":57},"# Then add execute back for directories only\n",[51,354,355,357,359,361,363,365,367,370,372],{"class":53,"line":107},[51,356,65],{"class":64},[51,358,69],{"class":68},[51,360,73],{"class":72},[51,362,76],{"class":68},[51,364,79],{"class":72},[51,366,82],{"class":68},[51,368,369],{"class":68}," a+x",[51,371,88],{"class":68},[51,373,91],{"class":68},[10,375,377],{"id":376},"handling-special-file-types","Handling Special File Types",[144,379,381],{"id":380},"executable-scripts","Executable Scripts",[15,383,384,385,388,389,388,392,395],{},"Scripts (",[19,386,387],{},".sh",", ",[19,390,391],{},".py",[19,393,394],{},".js"," with shebangs) need execute permission:",[42,397,399],{"className":44,"code":398,"language":46,"meta":47,"style":47},"# After setting 644 on all files, add execute back for scripts\nfind \u002Fvar\u002Fwww -type f -name \"*.sh\" -exec chmod 755 {} +\n",[19,400,401,406],{"__ignoreMap":47},[51,402,403],{"class":53,"line":54},[51,404,405],{"class":57},"# After setting 644 on all files, add execute back for scripts\n",[51,407,408,410,412,414,416,419,422,424,426,428,430],{"class":53,"line":61},[51,409,65],{"class":64},[51,411,69],{"class":68},[51,413,73],{"class":72},[51,415,116],{"class":68},[51,417,418],{"class":72}," -name",[51,420,421],{"class":68}," \"*.sh\"",[51,423,79],{"class":72},[51,425,82],{"class":68},[51,427,85],{"class":72},[51,429,88],{"class":68},[51,431,91],{"class":68},[144,433,435],{"id":434},"web-server-document-roots","Web Server Document Roots",[15,437,438],{},"A secure web root typically follows this pattern:",[149,440,441,457],{},[152,442,443],{},[155,444,445,448,451,454],{},[158,446,447],{},"Path",[158,449,450],{},"Permissions",[158,452,453],{},"Owner",[158,455,456],{},"Group",[168,458,459,475,488,499,511,522],{},[155,460,461,466,469,472],{},[173,462,463],{},[19,464,465],{},"\u002Fvar\u002Fwww\u002F",[173,467,468],{},"755",[173,470,471],{},"root",[173,473,474],{},"www-data",[155,476,477,482,484,486],{},[173,478,479],{},[19,480,481],{},"\u002Fvar\u002Fwww\u002Fhtml\u002F",[173,483,468],{},[173,485,474],{},[173,487,474],{},[155,489,490,493,495,497],{},[173,491,492],{},"Directories",[173,494,468],{},[173,496,474],{},[173,498,474],{},[155,500,501,504,507,509],{},[173,502,503],{},"Static files",[173,505,506],{},"644",[173,508,474],{},[173,510,474],{},[155,512,513,516,518,520],{},[173,514,515],{},"Upload directories",[173,517,468],{},[173,519,474],{},[173,521,474],{},[155,523,524,527,530,532],{},[173,525,526],{},"Config files",[173,528,529],{},"640",[173,531,471],{},[173,533,474],{},[144,535,537],{"id":536},"shared-group-directories","Shared Group Directories",[15,539,540],{},"For directories where a group needs write access:",[42,542,544],{"className":44,"code":543,"language":46,"meta":47,"style":47},"# Set SGID bit so new files inherit the group\nfind \u002Fvar\u002Fwww\u002Fshared -type d -exec chmod 2775 {} +\nfind \u002Fvar\u002Fwww\u002Fshared -type f -exec chmod 664 {} +\n",[19,545,546,551,573],{"__ignoreMap":47},[51,547,548],{"class":53,"line":54},[51,549,550],{"class":57},"# Set SGID bit so new files inherit the group\n",[51,552,553,555,558,560,562,564,566,569,571],{"class":53,"line":61},[51,554,65],{"class":64},[51,556,557],{"class":68}," \u002Fvar\u002Fwww\u002Fshared",[51,559,73],{"class":72},[51,561,76],{"class":68},[51,563,79],{"class":72},[51,565,82],{"class":68},[51,567,568],{"class":72}," 2775",[51,570,88],{"class":68},[51,572,91],{"class":68},[51,574,575,577,579,581,583,585,587,590,592],{"class":53,"line":94},[51,576,65],{"class":64},[51,578,557],{"class":68},[51,580,73],{"class":72},[51,582,116],{"class":68},[51,584,79],{"class":72},[51,586,82],{"class":68},[51,588,589],{"class":72}," 664",[51,591,88],{"class":68},[51,593,91],{"class":68},[15,595,130,596,599],{},[19,597,598],{},"2"," (SGID) ensures new files are created with the directory's group rather than the creator's primary group.",[10,601,603],{"id":602},"common-recursive-mistakes","Common Recursive Mistakes",[144,605,607],{"id":606},"_1-chmodding-from-root","1. Chmodding from Root",[42,609,611],{"className":44,"code":610,"language":46,"meta":47,"style":47},"# DANGEROUS — breaks system binaries and configs\nchmod -R 755 \u002F\n",[19,612,613,618],{"__ignoreMap":47},[51,614,615],{"class":53,"line":54},[51,616,617],{"class":57},"# DANGEROUS — breaks system binaries and configs\n",[51,619,620,622,624,626],{"class":53,"line":61},[51,621,137],{"class":64},[51,623,305],{"class":72},[51,625,85],{"class":72},[51,627,628],{"class":68}," \u002F\n",[15,630,631,632,635,636,639],{},"Always specify your target directory explicitly. Never run recursive chmod on ",[19,633,634],{},"\u002F"," or ",[19,637,638],{},"\u002Fetc",".",[144,641,643],{"id":642},"_2-forgetting-hidden-files","2. Forgetting Hidden Files",[15,645,646,648,649,651,652,655,656,659],{},[19,647,32],{}," processes hidden files, but ",[19,650,65],{}," patterns like ",[19,653,654],{},"*.txt"," won't match ",[19,657,658],{},".env",". If you need to exclude hidden files:",[42,661,663],{"className":44,"code":662,"language":46,"meta":47,"style":47},"find \u002Fvar\u002Fwww -type f -not -path '*\u002F\\.*' -exec chmod 644 {} +\n",[19,664,665],{"__ignoreMap":47},[51,666,667,669,671,673,675,678,681,684,686,688,690,692],{"class":53,"line":54},[51,668,65],{"class":64},[51,670,69],{"class":68},[51,672,73],{"class":72},[51,674,116],{"class":68},[51,676,677],{"class":72}," -not",[51,679,680],{"class":72}," -path",[51,682,683],{"class":68}," '*\u002F\\.*'",[51,685,79],{"class":72},[51,687,82],{"class":68},[51,689,123],{"class":72},[51,691,88],{"class":68},[51,693,91],{"class":68},[144,695,697],{"id":696},"_3-modifying-symlink-targets","3. Modifying Symlink Targets",[15,699,700,702,703,706],{},[19,701,137],{}," follows symlinks and modifies the target file. This can accidentally change permissions outside your intended directory tree. Use ",[19,704,705],{},"-P"," with find to avoid following symlinks:",[42,708,710],{"className":44,"code":709,"language":46,"meta":47,"style":47},"find -P \u002Fvar\u002Fwww -type f -exec chmod 644 {} +\n",[19,711,712],{"__ignoreMap":47},[51,713,714,716,719,721,723,725,727,729,731,733],{"class":53,"line":54},[51,715,65],{"class":64},[51,717,718],{"class":72}," -P",[51,720,69],{"class":68},[51,722,73],{"class":72},[51,724,116],{"class":68},[51,726,79],{"class":72},[51,728,82],{"class":68},[51,730,123],{"class":72},[51,732,88],{"class":68},[51,734,91],{"class":68},[10,736,738],{"id":737},"dry-run-first","Dry Run First",[15,740,741],{},"Before running recursive chmod, preview what would change:",[42,743,745],{"className":44,"code":744,"language":46,"meta":47,"style":47},"# List all files that would be modified\nfind \u002Fvar\u002Fwww -type f ! -perm 644 -print\nfind \u002Fvar\u002Fwww -type d ! -perm 755 -print\n",[19,746,747,752,773],{"__ignoreMap":47},[51,748,749],{"class":53,"line":54},[51,750,751],{"class":57},"# List all files that would be modified\n",[51,753,754,756,758,760,762,765,768,770],{"class":53,"line":61},[51,755,65],{"class":64},[51,757,69],{"class":68},[51,759,73],{"class":72},[51,761,116],{"class":68},[51,763,764],{"class":68}," !",[51,766,767],{"class":72}," -perm",[51,769,123],{"class":72},[51,771,772],{"class":72}," -print\n",[51,774,775,777,779,781,783,785,787,789],{"class":53,"line":94},[51,776,65],{"class":64},[51,778,69],{"class":68},[51,780,73],{"class":72},[51,782,76],{"class":68},[51,784,764],{"class":68},[51,786,767],{"class":72},[51,788,85],{"class":72},[51,790,772],{"class":72},[15,792,793],{},"Only apply changes if the list looks correct.",[10,795,797],{"id":796},"related-guides","Related Guides",[799,800,801,809,815],"ul",{},[802,803,804],"li",{},[805,806,808],"a",{"href":807},"\u002Fguides\u002Fchmod-guide","Chmod Guide",[802,810,811],{},[805,812,814],{"href":813},"\u002Fguides\u002Flinux-file-permissions","Linux File Permissions",[802,816,817],{},[805,818,820],{"href":819},"\u002Fguides\u002Funix-permissions-reference","Unix Permissions Reference",[10,822,824],{"id":823},"try-it-yourself","Try It Yourself",[15,826,827],{},"Calculate chmod values visually and see exactly what each permission set allows. Our free tool converts between numeric, symbolic, and binary representations.",[15,829,830,831],{},"👉 ",[805,832,834],{"href":833},"\u002Ftools\u002Fchmod-calculator",[835,836,837],"strong",{},"Free Chmod Calculator",[839,840,841],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":47,"searchDepth":61,"depth":61,"links":843},[844,845,848,849,852,857,862,863,864],{"id":12,"depth":61,"text":13},{"id":36,"depth":61,"text":37,"children":846},[847],{"id":146,"depth":94,"text":147},{"id":205,"depth":61,"text":206},{"id":286,"depth":61,"text":287,"children":850},[851],{"id":321,"depth":94,"text":322},{"id":376,"depth":61,"text":377,"children":853},[854,855,856],{"id":380,"depth":94,"text":381},{"id":434,"depth":94,"text":435},{"id":536,"depth":94,"text":537},{"id":602,"depth":61,"text":603,"children":858},[859,860,861],{"id":606,"depth":94,"text":607},{"id":642,"depth":94,"text":643},{"id":696,"depth":94,"text":697},{"id":737,"depth":61,"text":738},{"id":796,"depth":61,"text":797},{"id":823,"depth":61,"text":824},"2026-05-28","How to apply chmod recursively while keeping files and directories at different permission levels.","md",{"immutable":97},"\u002Fguides\u002Fchmod-recursive-permissions",6,{"title":5,"description":866},"guides\u002Fchmod-recursive-permissions","2kwB9pRb0spWysR4nXgSOpZZSBt1am2AiLNavUpdaEc",1780401332118]