Chmod 재귀적으로 제외한 모든 파일을 어떻게 디렉터리용?

Chmod 에 어떻게 755 없고 모든 디렉터리 파일 (계속)?

Chmod (재귀적으로) 역, how to 파일만 없고 디렉터리입니다?

질문에 대한 의견 (2)
해결책

, 디렉터리용 재귀적으로 열거하십시오 read&amp autoexec. 권한:

find /path/to/base/dir -type d -exec chmod 755 {} +
    • 재귀적으로 열거하십시오 파일을 읽기 권한:
find /path/to/base/dir -type f -exec chmod 644 {} +

또는, 많으면 객체를 프로세스:

chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)

Chmod '또는' 줄일 수 있다.

find /path/to/base/dir -type d -print0 | xargs -0 chmod 755 
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
해설 (5)

그러나 이러한 종류의 주된 이유는 디렉터리용 755 로 설정할 수 있는 것은 파일을 644. 이 경우 there& # 39 에 비해 약간 빠른 길 찾기 nik& # 39 의 ',' 예:

chmod -R u+rwX,go+rX,go-w /path

의미:

  • '-r' = 재귀적으로.
  • '' = u+rwX 읽기, 쓰기, 실행 수 있습니다.
  • '및' = 그룹 및 기타 실행하십시오 go+rX 읽을 수 있습니다.
  • 'gnu. w can& 쓰지 않고' = 그룹 및 기타 # 39.

여기서 주의해야 할 것은 중요한 건 'X' x '다른' 소문자화 대문자화 역할을 한다. 우리가 할 수 있는 수동 검토완료:

&gt. 이 경우 또는 모든 실행 / 실행 / 검색 비트 파일이 디렉토리에 있는 검색 비트가 설정되지 원본 (수정되지 않은) 모드.

즉, chmod u+X 실행 파일에 대한 won& # 39, t 설정되었습니다 약어입니다. # 39 에 대해 이미 설정된 it& 그칠 경우 설정되었습니다 g+X 및 사용자.

해설 (7)

그런데 이 파일을 사용할 수 있도록 스케쳐내 644 로 설정되어 있는 파일의 경로를 autoexec. 플래깅 분리하십시오 플래깅 실행하십시오 먼저 합니다. # 39 를 사용하고 있는 파일의 플래깅 실행하십시오 +x doesn&, t 분리하십시오 할꺼이나.

예:

chmod -R ugo-x,u+rwX,go+rX,go-w path

업데이트: 이 때문에 실패할 것으로, 따라서 모든 파일을 오네스쿠터블 디렉토리에는 첫 번째 변경 (우고 x) 는 그 아래에 바뀌지 않습니다.

해설 (2)

내가 내 자신을 좀 스크립트입니다 엔드입니다 쓰기로 했다.

[재귀 chmod 스크립트를 디렉터리 및 / 또는 파일 - 사진을] (https://gist.github.com/3731497/):

chmodr.sh

#!/bin/sh
# 
# chmodr.sh
#
# author: Francis Byrne
# date: 2011/02/12
#
# Generic Script for recursively setting permissions for directories and files
# to defined or default permissions using chmod.
#
# Takes a path to recurse through and options for specifying directory and/or 
# file permissions.
# Outputs a list of affected directories and files.
# 
# If no options are specified, it recursively resets all directory and file
# permissions to the default for most OSs (dirs: 755, files: 644).

# Usage message
usage()
{
  echo "Usage: $0 PATH -d DIRPERMS -f FILEPERMS"
  echo "Arguments:"
  echo "PATH: path to the root directory you wish to modify permissions for"
  echo "Options:"
  echo " -d DIRPERMS, directory permissions"
  echo " -f FILEPERMS, file permissions"
  exit 1
}

# Check if user entered arguments
if [ $# -lt 1 ] ; then
 usage
fi

# Get options
while getopts d:f: opt
do
  case "$opt" in
    d) DIRPERMS="$OPTARG";;
    f) FILEPERMS="$OPTARG";;
    \?) usage;;
  esac
done

# Shift option index so that $1 now refers to the first argument
shift $(($OPTIND - 1))

# Default directory and file permissions, if not set on command line
if [ -z "$DIRPERMS" ] && [ -z "$FILEPERMS" ] ; then
  DIRPERMS=755
  FILEPERMS=644
fi

# Set the root path to be the argument entered by the user
ROOT=$1

# Check if the root path is a valid directory
if [ ! -d $ROOT ] ; then
 echo "$ROOT does not exist or isn't a directory!" ; exit 1
fi

# Recursively set directory/file permissions based on the permission variables
if [ -n "$DIRPERMS" ] ; then
  find $ROOT -type d -print0 | xargs -0 chmod -v $DIRPERMS
fi

if [ -n "$FILEPERMS" ] ; then
  find $ROOT -type f -print0 | xargs -0 chmod -v $FILEPERMS
fi

하지만 이 또한 기본적으로 높여줍니까 재귀 chmod 조금 유연성을 명령행을 옵션 (세트 디렉터리입니다 및 / 또는 파일 권한, 또는 제외할지 이 모든 것이 모두 자동으로 재설정됩니다 755 644). 또한 시나리오용으로 몇 가지 오류가 있는지 확인합니다.

이에 대해 내 블로그에 내가 있다 "고 했다.

해설 (0)

, 디렉터리용 재귀적으로 열거하십시오 read&amp autoexec. 권한:

find /path/to/base/dir -type d -exec chmod 755 {} \;
    • 재귀적으로 열거하십시오 파일을 읽기 권한:
find /path/to/base/dir -type f -exec chmod 644 {} \;

베터 레이트 댄 네버 렛 미 업그레이드합니다 nik& # 39 의 오토메이티드 측의 수정. 천천히, 하지만 내 솔루션은 작동하잖아 대상으로선택된 any 여러 파일을 함께 sudo 일반적으로 파일 이름, 기호 없이 실행할 수 있습니다 (단, 다른 파일을 함께 하고 바랄 수도 있다고 발견하십시오 sudo).

해설 (4)

이 시도하시겠습니까 파이썬 스크립트. 단 두 syscall 파일별 시작 프로세스 및 it 필요하지 않습니다. 이와는 별도로 구축하는 C 에서, 이 될 가능성이 가장 빠른 길을 그렇게 (내가 필요한 파일 시스템 파일을 모두 15 만 777 로 설정되어 있던 迈向 수리입니다.)

#!/usr/bin/python3
import os
for par, dirs, files in os.walk('.'):
    for d in dirs:
        os.chmod(par + '/' + d, 0o755)
    for f in files:
        os.chmod(par + '/' + f, 0o644)

내 주변에 가 필요한 경우 지난해 이후 일부 특수 파일 / catch 시도하시겠습니까 chmod 히모딩 못했습니다.

해설 (0)

'나무' 를 사용할 수도 있습니다.

tree -faid /your_directory | xargs -L1 -I{} bash -c 'sudo chmod 755 "$1"' -- '{}'

추가 및 스케쳐내 폴더에서는 초음파요 볼 수도 있습니다.

 tree -faid /your_directory | xargs -L1 -I{} bash -c 'sudo chmod 755 "$1" && echo$1' -- '{}'
해설 (5)

예를 들어 다음 bash 스크립트입니다 사용할 수 있습니다. 반드시 give it 실행가능파일 권한 (755). 현재 디렉토리이며 사용하여 간단히 ./autochmod.sh ./autochmod.sh &amp dir&amp, gt, lt;; 다른 이름을 지정할 수 있습니다.

#!/bin/bash

if [ -e $1 ]; then
    if [ -d $1 ];then
        dir=$1
    else
        echo "No such directory: $1"
        exit
    fi
else
    dir="./"
fi

for f in $(ls -l $dir | awk '{print $8}'); do
    if [ -d $f ];then
        chmod 755 $f
    else
        chmod 644 $f
    fi
done
해설 (2)