mkdir的"-p"选项

use*_*866 86 unix command-line directory-structure command-line-arguments

所以这似乎不是一个非常复杂的问题,但我找不到答案.我对-p选项在Unix中的作用感到困惑.我在创建子目录时使用它进行实验室分配,然后在该子目录中使用另一个子目录.它看起来像这样:

mkdir -p cmps012m/lab1
Run Code Online (Sandbox Code Playgroud)

这是在具有正常权限的私人目录中(rlidwka).提前致谢!哦,有人会介意对"rlidwka"的含义做一些解释吗?我不是Unix的总菜鸟,但我并不熟悉这意味着什么.希望这个问题不是太模糊.

Pau*_* Bu 124

手册页是您可以找到的最佳信息来源......并且触手可及:man mkdir产生关于-p开关的信息:

-p, --parents
    no error if existing, make parent directories as needed
Run Code Online (Sandbox Code Playgroud)

用例示例:假设我想创建目录hello/goodbye但不存在:

$mkdir hello/goodbye
mkdir:cannot create directory 'hello/goodbye': No such file or directory
$mkdir -p hello/goodbye
$
Run Code Online (Sandbox Code Playgroud)

-p创造了两者,hellogoodbye

这意味着该命令将创建满足您请求的所有目录,而不是在该目录存在的情况下返回任何错误.

关于rlidwka,谷歌有一个很好的记忆缩写词:).我的搜索返回了这个例子: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. 
Run Code Online (Sandbox Code Playgroud)

因此rlidwka意味着:所有权限.

值得一提的是,正如@KeithThompson在评论中指出的那样,并非所有Unix系统都支持ACL.所以rlidwka概念可能不适用于此.

  • 这个答案是最简单的说法"RTFM,让我谷歌为你",我喜欢它.我曾经是一个不知道任何事情的noobie实习生,忘了在问我的经理之前我应该​​去谷歌.对这些新人轻松一点; 有时很难弄清楚谷歌的内容.你不知道你不知道什么.但是经过多年的努力,每个人都更加熟练地使用谷歌搜索. (3认同)
  • @Dagrooms 顺便说一句,我来这里是因为我不太明白手册中写的一句话描述! (3认同)
  • 但并非所有类 Unix 系统都支持 ACL,因此 `rlidwka` 可能有意义,也可能没有意义。 (2认同)

Rah*_*hul 6

-p|--parent如果您尝试使用方法创建目录,将使用该top-down方法。这将创建父目录,然后是子目录,依此类推,如果不存在的话。

-p, --parents 如果存在则没有错误,根据需要创建父目录

关于rlidwka它意味着给予完全或管理访问权限。在这里找到它https://itservices.stanford.edu/service/afs/intro/permissions/unix


Ami*_*esh 5

mkdir [-switch] 文件夹名

-p 是一个可选的开关,它会创建子文件夹和父文件夹,即使父文件夹不存在。

从手册页:

-p, --parents no error if existing, make parent directories as needed
Run Code Online (Sandbox Code Playgroud)

例子:

mkdir -p storage/framework/{sessions,views,cache}
Run Code Online (Sandbox Code Playgroud)

这将在框架文件夹内创建子文件夹会话、视图、缓存,而不管“框架”之前是否可用。