developer tip

mkdir의 "-p"옵션

optionbox 2020. 9. 22. 08:03
반응형

mkdir의 "-p"옵션


그래서 이것은 제가 가진 매우 복잡한 질문처럼 보이지는 않지만 대답을 찾을 수 없습니다. -pUnix 에서 옵션이 수행하는 작업에 대해 혼란 스럽습니다 . 하위 디렉터리를 만들고 그 안에 다른 하위 디렉터리를 만드는 동안 랩 할당에 사용했습니다. 다음과 같이 보였습니다.

mkdir -p cmps012m/lab1

이것은 일반 권한 ( rlidwka)을 가진 개인 디렉토리에 있습니다. 아, 그리고 누군가가 무슨 rlidwka인지에 대해 조금 설명해 주 시겠습니까? 나는 유닉스에 대해 완전히 멍청한 사람은 아니지만 이것이 무엇을 의미하는지 잘 알지 못합니다. 너무 모호한 질문이 아니기를 바랍니다.


man 페이지는 당신이 찾을 수있는 최고의 정보 소스입니다 ... 그리고 당신의 손끝에 있습니다 : 스위치 man mkdir에 대해 이것을 산출합니다 -p:

-p, --parents
    no error if existing, make parent directories as needed

사용 사례 예 : 디렉터리를 만들고 hello/goodbye싶지만 존재하지 않는다고 가정 합니다.

$mkdir hello/goodbye
mkdir:cannot create directory 'hello/goodbye': No such file or directory
$mkdir -p hello/goodbye
$

-p만들어 모두 hellogoodbye

, 명령이 요청을 수행하는 데 필요한 모든 디렉토리를 생성하고 해당 디렉토리가있는 경우 오류를 반환하지 않습니다 .

에 대해 rlidwkaGoogle은 약어에 대한 아주 좋은 메모리를 가지고 있습니다. :). 내 검색 결과가 다음과 같습니다. http://www.cs.cmu.edu/~help/afs/afs_acls.html

 Directory permissions

l (lookup)
    Allows one to list the contents of a directory. It does not allow the reading of files. 
i (insert)
    Allows one to create new files in a directory or copy new files to a directory. 
d (delete)
    Allows one to remove files and sub-directories from a directory. 
a (administer)
    Allows one to change a directory's ACL. The owner of a directory can always change the ACL of a directory that s/he owns, along with the ACLs of any subdirectories in that directory. 

File permissions

r (read)
    Allows one to read the contents of file in the directory. 
w (write)
    Allows one to modify the contents of files in a directory and use chmod on them. 
k (lock)
    Allows programs to lock files in a directory. 

따라서 rlidwka의미 : 모든 권한에 .

@KeithThompson이 주석에서 지적했듯이 모든 Unix 시스템이 ACL을 지원하는 것은 아니라는 점을 언급 할 가치가 있습니다. 그래서 아마도 rlidwka개념이 여기에 적용되지 않을 것입니다.


-p|--parent will be used if you are trying to create a directory with top-down approach. That will create the parent directory then child and so on iff none exists.

-p, --parents no error if existing, make parent directories as needed

About rlidwka it means giving full or administrative access. Found it here https://itservices.stanford.edu/service/afs/intro/permissions/unix.


mkdir [-switch] foldername

-p is a switch which is optional, it will create subfolder and parent folder as well even parent folder doesn't exist.

From the man page:

-p, --parents no error if existing, make parent directories as needed

Example:

mkdir -p storage/framework/{sessions,views,cache}

This will create subfolder sessions,views,cache inside framework folder irrespective of 'framework' was available earlier or not.


Note that -p is an argument to the mkdir command specifically, not the whole of Unix. Every command can have whatever arguments it needs.

In this case it means "parents", meaning mkdir will create a directory and any parents that don't already exist.


PATH: Answered long ago, however, it maybe more helpful to think of -p as "Path" (easier to remember), as in this causes mkdir to create every part of the path that isn't already there.

mkdir -p /usr/bin/comm/diff/er/fence

if /usr/bin/comm already exists, it acts like: mkdir /usr/bin/comm/diff mkdir /usr/bin/comm/diff/er mkdir /usr/bin/comm/diff/er/fence

As you can see, it saves you a bit of typing, and thinking, since you don't have to figure out what's already there and what isn't.

참고URL : https://stackoverflow.com/questions/22737933/mkdirs-p-option

반응형