[Unix.C]Files and Directories
stat, fstat, and lstat Functions
本部分讨论的内容主要围绕3个stat函数及其返回值。
| #include <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf); int fstat(int filedes, struct stat *buf); int lstat(const char *restrict pathname, struct stat *restrict buf); |
stat函数返回pathname的stat结构体。
fstat返回fd代表的文件的stat结构体。
lstat与stat很相似,但是当pathname是一个软链接时,lstat返回的是软链接的信息,而不是软链接指向的文件。
File Types
文件类型
regular file, directory file, block special file, character special file, FIFO(pipe), socket, symbolic link.
根据stat结构体中的st_mode判断文件类型
- S_ISREG():regular file
- S_ISDIR():directory file
- S_ISCHR():character special file
- S_ISBLK():block special file
- S_ISFIFO():pipe or FIFO
- S_ISLNK():symbolic link
- S_ISSOCK():socket
- S_TYPEISMQ():message queue
- S_TYPEISSEM():semaphore
- S_TYPEISSHM():shared memory object
access函数
测试当前用户拥有的文件权限
| #include <unistd.h> int access(const char *pathname, int mode); |
mode取值:man 2 access查看帮助文档
umask函数
设置文件被创建时的权限
| #include <sys/stat.h> mode_t umask(mode_t cmask); |
cmask取值:man 2 umask查看帮助文档
chmod/fchmod函数
更改文件的权限
| #include <sys/stat.h> int chmod(const char *pathname, mode_t mode); int fchmod(int filedes, mode_t mode); |
mode取值:man 2 chmod查看帮助文档
chown/fchown/lchown函数
更改文件的uid&gid
| #include int chown(const char *pathname, uid_t owner, gid_t group); int fchown(int filedes, uid_t owner, gid_t group); int lchown(const char *pathname, uid_t owner, gid_t group); |
[Unix.C]Files and Directories的更多相关文章
- 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories
The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk ...
- Files and Directories
Files and Directories Introduction In the previous chapter we coveredthe basic functions that pe ...
- Notes for Apue —— chapter 4 Files and Directories(文件和目录)
4.1 Introduction 4.2 stat, fstat, fstatat, and lstat Functions The lstat function is similar to stat ...
- 【原】The Linux Command Line - Manipulation Files And Directories
cp - Copy Files and directories mv - move/rename files and directories mkdir - create directories rm ...
- How to ignore files and directories in subversion?
Step 1 Copy the files and directories to other place. Step 2 Delete the files and directories. Step ...
- Getting svn to ignore files and directories
August 27, 2013Software Developmentresources, subversion, svn, tutorial, version control Who knew it ...
- UNIX高级环境编程(4)Files And Directories - umask、chmod、文件系统组织结构和链接
本篇主要介绍文件和文件系统中常用的一些函数,文件系统的组织结构和硬链接.符号链接. 通过对这些知识的了解,可以对Linux文件系统有更为全面的了解. 1 umask函数 之前我们已经了解了每个文件 ...
- UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作
1 File Times 每个文件会维护三个时间字段,每个字段代表的时间都不同.如下表所示: 字段说明: st_mtim(the modification time)记录了文件内容最后一次被修改的时 ...
- UNIX高级环境编程(3)Files And Directories - stat函数,文件类型,和各种ID
在前面的两篇,我们了解了IO操作的一些基本操作函数,包括open.read和write. 在本篇我们来学习一下文件系统的其他特性和一个文件的属性,涉及的函数功能包括: 查看文件的所有属性: 改变文件所 ...
随机推荐
- rapidxml对unicode的支持
为了提高duilib创建布局控件的效率,在LuaDui项目中使用rapidxml解析器替换了duilib库自带的xml解析器. duilib使用unicode编译,所以rapidxml需要解析unic ...
- layerX && layerY
转载:https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/layerX UIEvent.layerX 非标准 这个属性是非标准的属性,并且 ...
- uboot下 Nand flash 启动 内核与根文件系统
u-boot版本: u-boot-2010.03_tekkamanninja修改的u-boot 1.将uboot通过j-link烧写到norflash,启动后 saveenv 将参数保存到 nandf ...
- [Caffe] ubuntu14.04下使用OpenBLAS加速Caffe
一.apt安装 sudo apt-get install libopenblas-dev 二.手动从source安装 1. 下载OpenBLAS并编译 git clone https://github ...
- 关于学习HTML5中自己犯的错误
7.1写错了 siblings()这个函数写成了sibling,在jQuery中并没有这个函数的定义 在查找错误的过程中,自己也发现了一个学习jQuery的网站http://www.365mini.c ...
- 网站开发常用jQuery插件总结(七)背景插件backstretch
一.backstretch插件功能 优化网站外观.主要用于设置页面背景图片,也可以设置html元素的背景图片.背景图片可以设置多张,在间隔时间内循环显示. 注 但是在设置背景图片时,如果图片过大,网站 ...
- Windows7 下安装 CentOS6.5
内容来自:http://blog.163.com/for_log/blog/static/2162830282013031031278/第一部分:安装前准备1. 准备两个fat32格式的分区,一个用于 ...
- js监听
IE浏览器监听: function attachEvent(string eventFlag, function eventFunc) eventFlag: 事件名称,但要加上on,如onclick. ...
- H-UI的前端处理验证,判断是否已经存在,比较健全的模板,可以自己添加一些校验
<input type="text" class="input-text" value="${detail.supportingname }&q ...
- C# net部署图片分布式存储服务器的小案例
如果web服务用户多了,访问多了,用户上传的图片,文件等内容放在一块,想必服务器是承受不住的,这个时候,我们就需要考虑分布式存储的方法了. 如图所示:一个web服务器拖2个图片服务器 如何做到用户上传 ...