mkdir
1,mkdir
Problem: You want to use the mkdir() function from the sys/stat.h POSIX header, but you don’t know what the mode_t argument should look like.
Solution:
For a detailed reference, see the Opengroup page on mkdir
The first argument should be obvious - just enter the path name of the directory you intend to create. If you use a std::string (in C++); use it’s c_str() member function to get a C string.
The second argument defines the permissions the newly created directory shall have. This How-to assumes you’re already familiar with Unix file permissions. If you are not, please read the corresponding Wikipedia Page.
First, decide which rights the directory shall have. This boils down to these 9 questions:
- Shall the owner be able to read/write/execute?
- Shall the group be able to read/write/execute?
- Shall everyone else (= others) be able to read/write/execute? The second argument has the type mode_t, but this is basically just an alias for any type of integer.
sys/stat.h provides you with several integers you can bytewise-OR (|) together to create your mode_t:
- User: S_IRUSR (read), S_IWUSR (write), S_IXUSR (execute)
- Group: S_IRGRP (read), S_IWGRP (write), S_IXGRP (execute)
- Others: S_IROTH (read), S_IWOTH (write), S_IXOTH (execute)
Additionally, some shortcuts are provided (basically a bitwise-OR combination of the above
- Read + Write + Execute: S_IRWXU (User), S_IRWXG (Group), S_IRWXO (Others)
- DEFFILEMODE: Equivalent of 0666 = rw-rw-rw-
- ACCESSPERMS: Equivalent of 0777 = rwxrwxrwx Therefore, to give only the user rwx (read+write+execute) rights whereas group members and others may not do anything, you can use any of the following mkdir() calls equivalently:
mkdir("mydir", S_IRUSR | S_IWUSR | S_IXUSR);
mkdir("mydir", S_IRWXU);
In order to give anyone any rights (mode 0777 = rwxrwxrwx), you can use any of the following calls equivalently:
mkdir("mydir", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
mkdir("mydir", S_IRWXU | S_IRWXG | S_IRWXO);
mkdir("mydir", ACCESSPERMS);
mkdir的更多相关文章
- 编译Openwrt的log
Openwrt配置: Target System (Ralink RT288x/RT3xxx) ---> Subtarget (MT7688 based boards) ---> Targ ...
- linux常用命令(3)mkdir命令
mkdir命令1 命令格式:mkdir [选项]目录名2 命令功能:通过 mkdir 命令可以实现在指定位置创建以 DirName(指定的文件名)命名的文件夹或目录.要创建文件夹或目录的用户必须对所创 ...
- mkdir,rmdir,cp,rm,mv,cat,touch用法
一.mkdir新建目录 1.进入tmp目录,查看该目录下面的子目录 [root@localhost ~]# cd /tmp[root@localhost tmp]# lshsperfdata_root ...
- mkdir创建目录
mkdir:make directories(创建目录) 创建目录的首要条件:在当前目录或者欲创建目录下,该用户具有写入权限,mkdir详细功能如下: 1.mkdir不接任何参数时,即mkdir di ...
- mkdir命令
[mkdir] 创建目录 mkdir ===make directory 命令格式: mkdir [OPTION]... DIRECTORY 命令功能: 通过 mkdir 命令可以实现在指 ...
- PHP mkdir 0777权限问题
在linux系统中,即使我们使用root帐号去手工执行php命令: mkdir('test', 0777); 结果文件的权限依然为: drwxr-xr-x 2 root root 4096 Jun 1 ...
- Linux mkdir 创建文件夹命令
介绍: 该命令创建指定的目录名,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录 语法: mkdir [-m] [-p] 目录名 选项介绍: -m: 对新建目录设置 ...
- 【YEOMAN】执行yo命令,报EACCES: permission denied, mkdir '/root/.config/configstore'
基础环境:CentOS7.Nodejs6.0之上,yo:1.8.4 在执行yo初始化webapp时,报错,错误内容如下: Error: EACCES: permission denied, mkdir ...
- Linux_用户级_常用命令(3):mkdir
Linux常用命令之mkdir 开篇语:懒是人类进步的源动力 本文原创,专为光荣之路公众号所有,欢迎转发,但转发请务必写出处! Linux常用命令第3集包含命令:mkdir (附赠tree命令,日期时 ...
- java mkdir()和mkdirs()的区别
boolean mkdir() 创建此抽象路径名指定的目录. boolean mkdirs() 创建此抽象路径名指定的目录,包括创建必需但不存在的父目录. 也就是说,mkdir只能创建 ...
随机推荐
- php中的正则表达式具体的说明案例
让我们看看两个非凡的字符:'^' 和 '$' 他们是分别用来匹配字符串的开始和结束,一下分别举例说明: "^The": 匹配以 "The"开头的字符串; &qu ...
- CSS系列:长度单位&字体大小的关系em rem px
em是相对长度单位.相对于当前对象内文本的字体尺寸.如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸. 任意浏览器的默认字体高都是16px.所有未经调整的浏览器都符合: 1em=1 ...
- GTX 770 (GK 104)
上周的这个时候,NVIDIA GeForce 700系列的旗舰产品GTX 780正式发布,传闻已久的GTX 700家族终于来了!虽然没有任何新架构.新特性的旗舰卡发布总让人觉得少点什么.但从性能上来说 ...
- selenium 使用笔记
下面一段代码是使用selenium访问网页一个小实例 #!/usr/bin/python# -*- coding: utf-8 -*- '''Created on Dec 6, 2013 @autho ...
- 升级xcode6和ios8后,unity遇到的一些小问题
升级最新的Xocde6后,如果不是最新版本的unity,虽然也可以也可以正常的build,但如果想通过unity连真机进行profile的话,就会在xocde中报错,这个的主要原因是unity的配置里 ...
- 撑起大规模PHP网站的开源工具
撑起大规模PHP网站的开源工具 百万级PHP站点Poppen.de的架构 在 2011年11月27日 那天写的 已经有 3957 次阅读了 感谢 参考或原文 服务器君一共花费了54.510 ...
- Bootstrap页面布局12 - BS表单元素的排版
首先看看这行代码: <label for='account'>帐 号</label> <input id='account' name='account' type='t ...
- 泌尿系统 Excretory system
https://zh.wikipedia.org/wiki/泌尿系统 泌尿系統,有時也歸類於排泄系統(Excretory system)的一部分,負責尿液的產生.運送.儲存與排泄.人類的泌尿系統包括左 ...
- javascript:void(0)与#整理
window.location.href="/signup/devicelogin.shtml"; 指跳转到引号的url地址 #包含了一个位置信息,默认的锚点#是top,网页的顶端 ...
- Lazarus IDE的几个小技术
delphi+cnpack用惯了,转移到lazarus有点难受是不是!其实,lazaurs的编辑器也是蛮强大的,支持代码补全,自动完成,模板编辑,多行缩进注释,选定代码后批量更改里面的单词!目前,我知 ...