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.

 

 

 

 

 

 

 

 

 

 

python3.5.2中pycharm中pip install xgboost出现No files/directories in...

在命令行窗口中或者在pycharm中pip install xgboost等包时可能会出现no files/directories等等问题,可以通过以下方法解决 1.现实出现pip版本不符可以更新版...
  • u010244645
  • u010244645
  • 2017年04月21日 21:52
  • 477

git 使用中的坑,无法pull 版本

git 使用中,遇到了一个很郁闷的问题,在linux 中能够使用pull 拉取代码,但在Windows下却提示 error: Updating the following directories wo...
  • chyin1024
  • chyin1024
  • 2017年05月26日 17:02
  • 388

Yocto: Building Yocto with meta-altera

https://rocketboards.org/foswiki/Documentation/YoctoDoraBuildWithMetaAltera Introduction Yoc...
  • sunjing_
  • sunjing_
  • 2017年10月30日 17:53
  • 210

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
  • 142

介绍个简单的命令 tar

在mac上做开发有段时间了,突然发现自己一直在使用工具,对于linux下的一些命令...
  • Vjunjun
  • Vjunjun
  • 2014年04月10日 17:45
  • 796

Zynq-Linux移植学习笔记之二-知识点

在zynq上进行Linux的移植并基于Linux进行驱动开发需要涉及到很多东西,用一张图说明要掌握哪些知识: 如上图所示,对开发驱动的人来说,既要懂软件也要懂硬件,软件上需要对操作系统结构和接...
  • jj12345jj198999
  • jj12345jj198999
  • 2017年01月18日 22:53
  • 1397

严重: Error waiting for multi-thread deployment of directories to completehostConfig.deployWar=Deployi

如果是tomcat 直接在windows-->preferences-->tomcat x(x:你使用的版本)-->jdk-->optional java vm arguments 里面填写 -Xms...
  • zhousiling123
  • zhousiling123
  • 2013年06月24日 14:51
  • 1212

CocosBuilder-Too Many Directories

cocosBuilder是一款很好用的cocos2d辅助开发工具。 网上的教程很多,但新版本的使用略有出入。我记一下。 下载下了工具后,新工程,File->New->New Project...
  • Liar0606
  • Liar0606
  • 2013年10月22日 14:24
  • 2626

Linux学习笔记之——起始篇

摘要:学习笔记目录、方便以后回顾、没有什么捷径可走、不断的记录、总结、练习、coding、coding。...
  • chenghuaying
  • chenghuaying
  • 2014年03月31日 16:47
  • 4760

代码质量管理平台SonarQube的安装、配置与使用

原文地址:https://www.cnblogs.com/qiumingcheng/p/7253917.html 主要记录下遇到问题的地方: 1、下载地址: sonarqube:http://w...
  • u012108512
  • u012108512
  • 2018年02月01日 15:01
  • 22
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:linux 学习笔记之 Files and Directories
举报原因:
原因补充:

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