mkdir's “-p” option

后端 未结 5 1817
南方客
南方客 2021-01-30 00:26

So this doesn\'t seem like a terribly complicated question I have, but it\'s one I can\'t find the answer to. I\'m confused about what the -p option does in Unix.

相关标签:
5条回答
  • 2021-01-30 01:02

    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.

    0 讨论(0)
  • 2021-01-30 01:13

    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.

    0 讨论(0)
  • 2021-01-30 01:14

    The man pages is the best source of information you can find... and is at your fingertips: man mkdir yields this about -p switch:

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

    Use case example: Assume I want to create directories hello/goodbye but none exist:

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

    -p created both, hello and goodbye

    This means that the command will create all the directories necessaries to fulfill your request, not returning any error in case that directory exists.

    About rlidwka, Google has a very good memory for acronyms :). My search returned this for example: 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. 
    

    Hence rlidwka means: All permissions on.

    It's worth mentioning, as @KeithThompson pointed out in the comments, that not all Unix systems support ACL. So probably the rlidwka concept doesn't apply here.

    0 讨论(0)
  • 2021-01-30 01:22

    -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.

    0 讨论(0)
  • 2021-01-30 01:24

    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.

    0 讨论(0)
提交回复
热议问题