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只能创建 ...
随机推荐
- java编译自动化
java编译自动化 http://h2ofly.blog.51cto.com/6834926/1545452?utm_source=tuicool&utm_medium=referral
- python深浅拷贝
赋值引用,多变量使用同内存.对于可变数据对象,修改其中一个,影响其他.浅拷贝,只拷贝数据父对象,不拷贝其中子对象.深拷贝,拷贝对象及其子对象. 赋值引用:(修改,所有多影响) list1=[1,2,3 ...
- 八、job管理
查看用法: [root@super65 ~]# salt-run -d|grep jobs'jobs.active:' #查看当前执行的job Return a report on all activ ...
- Reset RequiredFieldValidator 重置 验证控件
<td style="width:100px;">姓名<span class="must_star">*</span>< ...
- data structure | heap
#include <iostream> #include <string.h> using namespace std; template <class T> cl ...
- OpenCV学习笔记——形态学梯度操作
代码: #include<cv.h> #include<highgui.h> int main(void) { cvNamedWindow("cmp"); ...
- HTML5 javascript CSS3 jQuery Mobile一些好用的网站
jQueryMobile:学习 http://www.runoob.com/jquerymobile/jquerymobile-tutorial.html 百度 CDN: http://cdn.cod ...
- emacs+ensime+sbt打造spark源码阅读环境
欢迎转载,转载请注明出处,徽沪一郎. 概述 Scala越来越流行, Spark也愈来愈红火, 对spark的代码进行走读也成了一个很普遍的行为.不巧的是,当前java社区中很流行的ide如eclips ...
- Nginx 笔记与总结(10)Nginx 与 PHP 整合
Apache + PHP 的编译 和 Nginx + PHP 的编译,区别: Apache 一般把 PHP 当作自己的一个模块来启动: Nginx 则是把 HTTP 请求变量(如 get,user_a ...
- PHP 设计模式 笔记与总结(3)SPL 标准库
SPL 库的使用(PHP 标准库) 1. SplStack,SplQueue,SplHeap,SplFixedArray 等数据结构类 ① 栈(SplStack)(先进后出的数据结构) index.p ...