Chmod différent pour fichier & dossier

Pour changer des droits en fonction d’un répertoire ou d’un fichier en parcourant une arboressence :

Utilisation

Manuel

Définition dans les manuels :

xargs — build and execute command lines from standard input 
exec — execute commands and open, close, or copy file descriptors

Find et exec

La commande find couplée à exec :

# find <path> -type d -exec chmod 755 {} \;
# find <path> -type f -exec chmod 644 {} \;

Son équivalent avec les droits rxw :

# find <path> -type d -exec chmod u=rwx,go=rx {} \;
# find <path> -type f -exec chmod u=rw,go=r {} \;

Find et xargs

La commande find couplée à xargs :

find <path> -type f -print0 | xargs -0 chmod 666
find <path> -type d -print0 | xargs -0 chmod 777

Documentation

https://linux.die.net/man/3/exec
https://superuser.com/questions/51838/recursive-chmod-rw-for-files-rwx-for-directories
https://freebsd-questions.freebsd.narkive.com/raofRfPG/chmod-equivalent-to-find-commands

> Partager <