반응형
존재하지 않는 경우에만 mkdir
bash 스크립트에서 수행할 작업:
mkdir product;
스크립트를 두 번 이상 실행하면 다음 메시지가 표시됩니다.
mkdir: product: File exists
콘솔에서.
그래서 dir가 없는 경우에만 mkdir를 실행하려고 합니다.이것이 가능합니까?
테스트를 합니다.
[[ -d dir ]] || mkdir dir
또는 -p 옵션을 사용합니다.
mkdir -p dir
if [ ! -d directory ]; then
mkdir directory
fi
또는
mkdir -p directory
-p
경우 생성을(를) 사용할 수 있습니다.directory
하지 않습니다.
mkdir 하기 용-p
다른 효과도 있습니다.
-p Create intermediate directories as required. If this option is not specified, the full path prefix of each oper-
and must already exist. On the other hand, with this option specified, no error will be reported if a directory
given as an operand already exists. Intermediate directories are created with permission bits of rwxrwxrwx
(0777) as modified by the current umask, plus write and search permission for the owner.
mkdir -p
-p, --부모 오류 없음, 필요에 따라 부모 디렉토리 작성
사용해 보십시오.
mkdir -p dir;
참고:- 이렇게 하면 존재하지 않는 중간 디렉토리도 생성됩니다. 예를 들어,
mkdir -p를 확인하세요.
아니면 이것을 시도해 보세요:-
if [[ ! -e $dir ]]; then
mkdir $dir
elif [[ ! -d $dir ]]; then
echo "$Message" 1>&2
fi
언급URL : https://stackoverflow.com/questions/18622907/only-mkdir-if-it-does-not-exist
반응형
'code' 카테고리의 다른 글
Git 저장소 디렉터리 위치를 변경합니다. (0) | 2023.05.28 |
---|---|
String.빈 문자열을 무시하는 조인 메서드를 선택하시겠습니까? (0) | 2023.05.23 |
XmlSerializer - 유형을 반영하는 동안 오류가 발생했습니다. (0) | 2023.05.23 |
git + LaTeX 워크플로우 (0) | 2023.05.23 |
Linq에서 캐스트() 및 Oftype()을 사용하는 경우 (0) | 2023.05.23 |