#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h> ino_t get_inode(char *);
void printpathto(ino_t);
void inum_to_name(ino_t, char *, int); int main()
{
printpathto(get_inode("."));
printf("\n");
return 0;
} void printpathto(ino_t this_inode)
{
ino_t my_inode;
char its_name[BUFSIZ];
if (get_inode("..") != this_inode)
{
chdir("..");
inum_to_name(this_inode, its_name, BUFSIZ);
my_inode = get_inode(".");
printpathto(my_inode);
printf("/%s", its_name);
} } void inum_to_name(ino_t inode_to_find, char *namebuf, int buflen)
{
DIR *dir_ptr;
struct dirent *direntp;
dir_ptr = opendir(".");
if (dir_ptr == NULL)
{
perror(".");
exit(1);
}
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", inode_to_find);
exit(1);
} ino_t get_inode(char *fname)
{
struct stat info;
if (stat(fname, &info) == -1)
{
fprintf(stderr, "Cannot Stat");
perror(fname);
exit(1);
}
return info.st_ino;
}

pwd的实现的更多相关文章

  1. linux常用命令(2)pwd命令

    pwd 命令1 命令格式:pwd [选项]2 命令功能查看当前工作目录的完整路径3 常用参数一般不带任何参数如果目录是链接时:pwd -P 显示实际路径,而非使用链接路径4 常用实例:4.1 用pwd ...

  2. pwd命令

    [pwd]      打印当前的工作目录             pwd==print work director 命令格式: pwd [OPTION]... 命令功能: 打印当前工作目录的全路径 命 ...

  3. Linux命令学习总结:pwd命令

    命令简介: 该命令用来显示目前所在的工作目录.指令英文原义:print work directory 执行权限    :All User 指令所在路径:/usr/bin/pwd 或 /bin/pwd ...

  4. 每天一个linux命令(3):pwd命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  5. 【初级】linux pwd 命令详解及使用方法实战

    pwd:查看当前工作目录 前言: Linux中用 pwd 命令来查看”当前工作目录“的完整路径,就是经常提及的所在目录,多用在生产环境多级目录中查看当前所在路径,使用此命令能给运维人员/操作人员带来很 ...

  6. linux命令(3):pwd命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  7. linux-11 基本命令之 -工作期目录切换命令-pwd,cd,

    pwd 命令用于显示当前的工作目录,格式为:pwd[选项] @1.查看当前的工作路径: [root@localhost /]# pwd cd 命令用于切换工作路径 格式为:"cd 目录名称& ...

  8. Linux2:vi、ls、cd、pwd、mkdir、rm、mv、cp、cat、tail

    前言 从本篇文章开始,每篇文章将写10个Linux命令,个人的写作想法是: 1.常用的Linux命令,那些生僻的.不常用的就不写了 2.从实际考虑,只列出每个命令常见的用法和参数选项,有兴趣了解进一步 ...

  9. pwd, cd, ls, touch, mkdir, rmdir, rm

    学习Shell命令最好的资料当然的是$man, 绝对是查找命令的第一大杀器,但是我们有时只是想实现某个功能,甚至连这个命令是什么都不知道,又或者不想淹没在man里大段大段的英文里,大家可以参考Linu ...

  10. 每天一个Linux命令(3):pwd命令

    Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文 ...

随机推荐

  1. asp.net 通过 Handler 导出数据至excel (让用户下载)

    效果图: 代码: Export2Excel.ashx <%@ WebHandler Language="C#" CodeBehind="Export2Excel.a ...

  2. SPOJ 11840. Sum of Squares with Segment Tree (线段树,区间更新)

    http://www.spoj.com/problems/SEGSQRSS/ SPOJ Problem Set (classical) 11840. Sum of Squares with Segme ...

  3. Android应用开发经常使用知识

    在其它站点看到的,Mark一下 1.近期打开的应用不在近期任务列表中显示 android:excludeFromRecents="true" 设置为true,则排除在近期任务列表之 ...

  4. dos2unix与unix2dos之学习记录

    1. unix2dos与dos2unix这两个tool是用来干什么的? 这首先应该要说明一下背景知识: unix类操作系统下,换行字符是\n: 而早期的dos操作系统,其换行字符是由\r\n组成. 所 ...

  5. Reader开发(二)增加PDF阅读功能

    最近任务很多很忙,所以更新博客的速度很慢. 大概上周就为Reader加了一个PDF阅读的功能,但是一直没时间写上来.昨晚找一下文件发现扩展了功能的Demo居然在文件目录下看不到任何文件,但是却显示有文 ...

  6. 管理集群中的 crs 管理员

     管理集群中的 crs 管理员 oracle Managing CRS Administrators in the Cluster Use the following commands to ma ...

  7. HTML+CSS+JS - 5秒钟之后跳转页面

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c ...

  8. c语言,gdb

    Get gdb call stack http://blog.csdn.net/zoufeiyy/article/details/1490241 Debugging with GDB - Examin ...

  9. net core VS goang web

    asp.net core VS goang web[修正篇] 先前写过一篇文章:http://www.cnblogs.com/gengzhe/p/5557789.html,也是asp.net core ...

  10. 控件风格19种,必须倒背如流——其实就是控件所拥有的能力,即有条件使用VCL框架所提供的(功能)代码

    { New TControlStyles: csNeedsBorderPaint and csParentBackground. These two ControlStyles are only ap ...