linux 学习笔记之 Files and Directories

原创 2007年09月23日 18:33:00
  1.  file stat
int stat(const char * pathname, struct stat *info); 
int fstat(int fd, struct stat *info); 
int lstat(const char *pathname, struct stat *info);

The fstat function obtains information about the file that is already open on the descriptor filedes. The lstat function is similar to stat, but when the named file is a  symbolic link, lstat returns information about the symbolic link, not the file referenced by the symbolic link.

      2.      file access permissions

  • The file rule is that whenever we want to open any type of file by name, we must have execute permission in each directory mentioned in the name, including the current directory, if it is implied.   Read permission lets us read the directory(use ls command), write permission lets us create files below the directory and execute permission lets us pass through the directory when it is a component of a pathname what we are trying to access.
  • We must have write permission for a file to specify the O_TRUNC flag in the open function.
  • To delete an existing file, we need write permission and execute permission in the directory containing the file.

      3.  set-user-id, set-group-id, set-sticky-id

  • set-user-id(S_ISUID) : used in some file like /etc/passwd and print queue, the S_ISUID tell kernel run program as file owner
  • set-group-id(S_IGUID): tell kernel run program as file's group user
  • set-sticky-id(S_ISVTX): if the bits is set for a directory, the file in the directory can be removed or renamed only if the user has the write permission for the directory and one of the fellowing:  owns this file, owns the directory, is the superuser.

       4.   file truncation

int truncate(const char *pathname, off_t length);
int ftrruncate(int fd, off_t length);
  •  If the previous size of the file was greater than length, the data byond length is nolonger accessible.
  • If the previous sizeof the file was less than length, the effect is system dependent , but XSI-confofrmation system will increase the file size. If the implementation does extend a file, data between the old end of file and the new end of file will read as 0.

         5.

int link(const char *pathname, const char * newpath);
int symlink(const char *actualpath, const char * sympath);
int unlink(const char *pathname);
int remove(const char *pathname);
 
  • Many system disallow hard link to directory to prevent loops in the file system.
  • When a file is closed, kernel first checks the count of the number of process that have the file open, If this count has reached 0, the kernel then checks the link count; if  it is 0, file's contents are delete. If the set-sticky-id is set in this directory  we must have enough permission(see above).
  •  If the pathname is a symbolic link unlink removes the symbolic link, not the references by the link. There is no function to remove the file referenced by a symbolic link given the name of the link.
  •  We can also unlink a file or a directory with the remove function. For a file, remove is identical to unlink. For directory, remove is identical rmdir.
  • It is not required that actualpath exist when the symbolic link is created.

        6.  chdir, fchdir

int chdir(const char *pathname);
int fchdir(int fd);

            Each program if run is a separate process, so the current working directory of the shell is unaffected by the call to chdir in the program.

         7.    device special files

             Each file system on the same disk drive would usually have the same number, but a different minor number.

 

 

 

 

 

 

 

 

 

 

相关文章推荐

《APUE》Chapter 4 Files and directories (学习笔记加上自己的代码)

Files and directories 整个第四章都是围绕着三个stat函数展开的 #include int stat(const char *restrict pathname, struct...

Linux - 操作文件与目录(manipulating files and directories)

操作文件与目录(manipulating files and directories) 本文地址: http://blog.csdn.net/caroline_wendy/article/deta...

《APUE》chapter 6 System Data files and information 学习笔记(加上自己的代码)

System Data files and information

UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作

 UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作  1 File Times 每个文件会维护三个时间字段,每个字段代表的...

Files and Directories

FHSThis article we will look around a GNU/Linux System. The Filesystem Hierarchy Standard (FHS) defi...
  • myxyhg
  • myxyhg
  • 2016年06月14日 23:36
  • 126

UNIX高级环境编程(4)Files And Directories - umask、chmod、文件系统组织结构和链接

UNIX高级环境编程(4)Files And Directories - umask、chmod、文件系统组织结构和链接 本篇主要介绍文件和文件系统中常用的一些函数,文件系统的组...

Scrapy学习笔记九--Downloading and processing files and images

item pipelines 对爬取的数据进行处理,如下载图片,保存等等Files Pipeline 处理文件Images Pipeline 处理图片下载每个pipelines都需实现以下特色:...

学习实战完全笔记--JavaSE----流与文件(Streams and Files)

流与文件的定义 :一个对象,可以从中读入一组字节,就叫输入流;一个对象,可以从中输出一组字节,就叫输出流。 ( In the Java API, an object from which we ca...

scikit-learn学习笔记(二)load_files加载自己的文件

这里不讨论加载常用的公用数据集,而是讨论加载自己的原始数据(即,实际中遇到的数据) sklearn.datasets.load_files(container_path, description=...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:linux 学习笔记之 Files and Directories
举报原因:
原因补充:

(最多只允许输入30个字)