Portál AbcLinuxu, 4. května 2025 22:58
$find path/ -type d -exec chmod 0755 {} \;Nastaví všem souborům včetně podsouborů ve šložce path/ práva na 644 (rw- r-- r--)
$find path/ -type f -exec chmod 0644 {} \;
#!/bin/bash find ${1} -type f -print0 | xargs -0 chmod 644 find ${1} -type d -print0 | xargs -0 chmod 755
Chyba, parametr +X
nastaví x
je-li soubor adresář nebo je-li již alespoň u jednoho z user, group, other
toto právo nastaveno
#!/usr/bin/env python import os, stat, sys def chmod_r(directory, filemode, dirmode): queue = [directory] while queue: rootdir = queue.pop() for diritem in os.listdir(rootdir): itempath = os.path.join(rootdir, diritem) itemstat = os.lstat(itempath) if stat.S_ISDIR(itemstat.st_mode): queue.append(itempath) reqmode = dirmode elif stat.S_ISREG(itemstat.st_mode): reqmode = filemode else: continue if reqmode != stat.S_IMODE(itemstat.st_mode): os.chmod(itempath, reqmode) filemode = 0644 dirmode = 0755 chmod_r(sys.argv[1], filemode, dirmode)Ale je to rychlejší jen asi o třetinu a při menším počtu souborů se situace obrací. find-xargs-chmod je zatraceně dobře vyladěná kombinace.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.