所以这似乎不是一个非常复杂的问题,但我找不到答案。我对-p
选项在Unix中的作用感到困惑。我在创建子目录时使用它进行实验室分配,然后在该子目录中使用另一个子目录。它看起来像这样:
mkdir -p cmps012m/lab1
这是在具有正常权限的私人目录中(rlidwka
)。哦,有人会介意给rlidwka
的意思吗?我不是Unix的总菜鸟,但我并不熟悉这意味着什么。希望这个问题不是太模糊。
手册页是您可以找到的最佳信息来源......并且触手可及: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
创造了两个,hello
和goodbye
这意味着该命令将创建满足您请求的所有目录,而不是在该目录存在的情况下返回任何错误。
关于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.
因此rlidwka
意味着:所有权限。
值得一提的是,正如@KeithThompson在评论中指出的那样,并非所有Unix系统都支持ACL。因此,rlidwka
概念可能不适用于此。
如果您尝试使用-p|--parent
方法创建目录,将使用top-down
。这将创建父目录,然后创建子目录,依此类推,如果不存在则。
-p, - 如果存在则没有错误,根据需要创建父目录
关于rlidwka
它意味着提供完全或管理访问权限。在这里找到它https://itservices.stanford.edu/service/afs/intro/permissions/unix。
mkdir [-switch] foldername
-p
是一个可选的开关,它将创建子文件夹和父文件夹,甚至父文件夹也不存在。
从手册页:
-p, --parents no error if existing, make parent directories as needed
例:
mkdir -p storage/framework/{sessions,views,cache}
这将创建子文件夹会话,视图,框架文件夹内的缓存,而不管之前是否提供“框架”。
请注意,-p
是mkdir
命令的参数,而不是整个Unix。每个命令都可以包含所需的任何参数。
在这种情况下,它意味着“父母”,这意味着mkdir
将创建一个目录和任何尚未存在的父母。
路径:很久以前回答,将-p视为“路径”(更容易记住)可能更有帮助,因为这会导致mkdir创建路径中尚未存在的路径的每个部分。
mkdir -p / usr / bin / comm / diff / er / fence
如果/ usr / bin / comm已经存在,它的行为如下:mkdir / usr / bin / comm / diff mkdir / usr / bin / comm / diff / er mkdir / usr / bin / comm / diff / er / fence
正如您所看到的,它可以为您节省一些打字和思考,因为您不必弄清楚已经存在的内容和不存在的内容。