学习电脑,计算机系统故障维护,电脑技术,电脑知识学习-就上第二电脑网
当前位置: 首页 > 电脑知识 > 系统常识

w10电脑系统怎么关机Unix文件系统和pwd命令实现详解

 更新时间: 2019-07-21 20:28:45   作者:第二电脑网   来源:第二电脑网   浏览数:232   我要评论

1. 对于用户来讲Uix系统中硬盘上的文件组成一棵目录树。每个目录能包含文件和其他子目录。 目录树的深度几乎没有限制,当然如果你所创建的目录树太深,系统就会提醒超过范围,并

电脑技术002pc网认为此文章对《w10电脑系统怎么关机Unix文件系统和pwd命令实现详解》说的很在理,电脑技术002pc网为你提供最佳的电脑基础教程,操作系统。

函数原型int res=rename (const char* from,const char *to);

原理:复制链接到新的名字/位置再删除原来的链接

if(link("x","z")!=-1)

unlink("x");

命令 cd 对进程有影响,对目录本身没有影响

实现 头文件 #include <unistd.h>

函数原型 int res=chdir (const char *path);

14. pwd 命令的实现

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <dirent.h>

#include <string.h>

#include <unistd.h>

ino_t get_inode(char *);//get the inode number

void printpathto(ino_t);

void inum_to_name(ino_t,char *,int);//get the node name by its inode number

int main()

{

printpathto(get_inode("."));

putchar('\n');

return 0;

}

void printpathto(ino_t this_inode)

{

ino_t my_inode;

char its_name[BUFSIZ];

if(get_inode("..")!=this_inode)

{

chdir(".."); //up one dir

inum_to_name(this_inode,its_name,BUFSIZ); //get its name

my_inode=get_inode(".");

printpathto(my_inode); //itorater

printf("/%s",its_name);

}

}

void inum_to_name(ino_t inode_to_find,char *namebuf,int buflen)

{

DIR *dir_ptr; //the directory

struct dirent *direntp; //each entry

dir_ptr=opendir(".");

if(dir_ptr==NULL)

{

perror(".");

return;

}

while((direntp=readdir(dir_ptr))!=NULL)

{

if(direntp->d_ino==inode_to_find)

{

strncpy(namebuf,direntp->d_name,buflen);

namebuf[buflen-1]='\0';

closedir(dir_ptr);

return;

}

}

fprintf(stderr,"error looking for inum %d\n",(int)inode_to_find);

return;

}

ino_t get_inode(char *fname)

{

struct stat info;

if(stat(fname,&info)==-1)

{

fprintf(stderr,"Can not stat");

perror(fname);

return 1;

}

return info.st_ino;

}

运行结果:

caoli@caoli-laptop:~/workspace/test$ ./pwd1

/home/caoli/workspace/test

caoli@caoli-laptop:~/workspace/test$


更多:w10电脑系统怎么关机Unix文件系统和pwd命令实现详解
https://www.002pc.com/xitongchangshi/51.html

你可能感兴趣的pwd,Unix,详解,文件系统,命令,实现

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

  浙ICP备140365454号

©CopyRight 2008-2020 002pc.COM Inc All Rights Reserved. 第二电脑网 版权所有 联系QQ:282523118