学习笔记(linux高级编程)5

发布于:2024-06-28 ⋅ 阅读:(145) ⋅ 点赞:(0)

4.chdir

chdir ("/home/linux"); "../../"

fopen("1.mp4")

int chdir(const char *path);// /home/linux

功能:

    改变当前程序的工作路径

参数:

    path:改变到的路径

返回值:

    成功返回0

    失败返回-1

/home/linux/Desktop/Music

"file.txt"

chdir("/root");

"file.txt"

5.getcwd //pwd

char *getcwd(char *buf, size_t size);

功能:

    获得当前的工作路径

参数:

    buf:保存工作路径空间的首地址

    size:保存路径空间的长度

返回值:

    成功返回包含路径空间的字符串首地址

    失败返回NULL

6.mkdir

int a  =200;

int mkdir(const char *pathname, mode_t mode);//777  666 --x--x--x

功能:

    创建一个目录

    666-

参数:

    pathname:路径

    mode:

         mode & ~umask  0002

        

返回值:

    成功返回0

    失败返回-1

   

7.rmdir   rm -fr    rmdir

int rmdir(const char *pathname);

功能:

    删除一个空目录文件

参数:

    pathname:目录文件的名字

返回值:

    成功返回0

    失败返回-1

实现ls -l

drwxrwxr-x 2 linux linux 4096 Mar 22 19:31 ./

说明:

    d     rwx rwx r-x     2         linux  linux  4096       Mar 22 19:31      ./

文件类型  相关权限    目录          所有者 所在组 文件大小  最后被修改的时间  文件名

          用户        (子目录个数)

           所在组      文件

           其他人      (硬链接数)

           (用户组)

---------------------------

硬链接:

      同一个文件,多个名字。

软链接:

      某一个文件的快捷方式。

1.stat

int  stat(const  char  *path, struct stat *buf);

功能:

    获得文件的属性

参数:

    path: 文件的路径

    buf:  属性存放空间的首地址

返回值:

    成功返回0

    失败返回-1

      

All of these system calls return a stat structure, which contains the following fields:

       struct stat {

             dev_t     st_dev;     /* ID of device containing file */ unsigned long int

             ino_t     st_ino;     /* inode number */(*)   unsigned long int             

             mode_t    st_mode;    /* protection */(* 权限信息) unsigned int

             nlink_t   st_nlink;   /* number of hard links */(* 硬链接数)unsigned int

             uid_t     st_uid;     /* user ID of owner */ (*UID 用户id)unsigned int

             gid_t     st_gid;     /* group ID of owner */(*group 所在组ID)unsigned int

          dev_t     st_rdev;    /* device ID (if special file) */unsigned long long int

      off_t     st_size;    /* total size, in bytes */(*文件的大小)// long unsigned int

               blksize_t st_blksize; /* blocksize for file system I/O */  long int

               blkcnt_t  st_blocks;  /* number of 512B blocks allocated */long int

      time_t    st_atime;   /* time of last access */(*最后访问的时间)long unsigned int

               time_t    st_mtime;   /* time of last modification */ (*最后修改的时间)

         time_t    st_ctime;   /* time of last status change */(*最后的状态改变的时间)

           };

st_mode  --- 32

           1111 0000 0000 0000

           S_IFMT     0170000   bit mask for the file type bit fields

           S_IFSOCK   0140000   socket        //s    1100

           S_IFLNK    0120000   symbolic link //l    1010

           S_IFREG    0100000   regular file  //-    1000

           S_IFBLK    0060000   block device  //b     110

           S_IFDIR    0040000   directory     //d     100

           S_IFCHR    0020000   character device //c  010

           S_IFIFO    0010000   FIFO             //p  001

           

           S_ISUID    0004000   set UID bit

           S_ISGID    0002000   set-group-ID bit (see below)

           S_ISVTX    0001000   sticky bit (see below)

            //user

           S_IRWXU    00700     mask for file owner permissions

           S_IRUSR    00400     owner has read permission

           S_IWUSR    00200     owner has write permission

           S_IXUSR    00100     owner has execute permission

            //group

           S_IRWXG    00070     mask for group permissions

           S_IRGRP    00040     group has read permission

           S_IWGRP    00020     group has write permission

           S_IXGRP    00010     group has execute permission

           

            //others   //掩码

           S_IRWXO    00007     mask for permissions for others (not in group)

           S_IROTH    00004     others have read permission

           S_IWOTH    00002     others have write permission

           S_IXOTH    00001     others have execute permission


网站公告

今日签到

点亮在社区的每一天
去签到