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只能创建 ...
随机推荐
- 李洪强-C语言2-字符串
C语言字符串 一.字符串基础 注意:字符串一定以\0结尾. Printf(“yang\n”); 其中yang为字符串常量,“yang”=‘y’+‘a’+‘n’+‘g’+‘\0’.字符串由很多的字符 ...
- hdu
这道题因为某些位置要重复走,所以不能用标记的方法,但是为了提高效率,可以采用time[]数组和step[]数组来剪枝,很容易想到,当你从一条路劲走到(x,y)处的时间和步骤 比从另一条路劲走到(x,y ...
- uva10098 Generating Fast, Sorted Permutation
#include"iostream"#include"stdio.h"#include"string.h"#include"alg ...
- 一些Office 365的问题收集
1. 按照MS的最佳实践, 应该是先有本地域, 然后再有Office 365. 但是我们公司刚好相反, 于是按照前面的文章做完了硬关联, 但是现在发现对于那些原本就在Office 365上的用户的Pr ...
- Objective-C、C++和swift 的运行效率比较
自己做iOS开发,以后慢慢都要转swift,前段时间看到网上的一个帖子,说swift的运行效率奇低,觉得自己有必要验证一下. 我用了一个最简单的加法运算,从0加到10000000,看三种语言的时耗. ...
- 【转】C#文件操作大全
文件与文件夹操作主要用到以下几个类: 1.File类: 提供用于创建.复制.删除.移动和打开文件的静态方法,并协助创建 FileStream 对象. msdn:http://msdn.microsof ...
- apache日志文件太大的问题
apache日志文件太大的问题 处理Apache日志的两种方法 rotatelogs 是 Apache 2.2 中自带的管道日志程序 rotatelogs [ -l ] logfile [ rotat ...
- mysql 导入导出.sql文件
备份数据库(包含全部表和全部存储过程):C:\Documents and Settings\Administrator>mysqldump -h localhost -u root -p -R ...
- C++类型转化分析(1)
仔细想想地位卑贱的类型转换功能(cast),其在程序设计中的地位就象goto语句一样令人鄙视.但是它还不是无法令人忍受,因为当在某些紧要的关头,类型转换还是必需的,这时它是一个必需品. 不过C风格的类 ...
- 【转载】C内存分配
一.预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. ...