Re: [SLUG] fullname program

From: Kwan Lowe (kwan@digitalhermit.com)
Date: Sat Nov 08 2003 - 10:03:26 EST


> I've never been able to find this, and I've always wanted it. In Linux,
> there are the basename and the dirname programs. Very handy. I want a
> "fullname" program. You'd feed it a relative or absolute filename, and
> it would give you back the fully qualified filename. This ought to be
> doable in C, maybe using the inode number returned from a stat(2) call,
> but I can't find a routine to discern the full path from an inode
> number.
>
> Anyway, anyone know of a program like this, or what I might have to do
> to build one (in C)?
>

You'd think there was something already built :D Here's one (messy) way
of doing it:

#!/bin/sh
FINDME=`ls -i $1|awk '{print $1}'`
find / -inum $FINDME 2>/dev/null

The problem, of course, is that you're doing a find for each run.

I was working on a way to use a combination of pwd and the passed name to
get an actual path. It would do this:

CURDIR='pwd'
RAWNAME=$CURDIR/$1

I would then look for any "../" in RAWNAME and remove the same number of
leading directories as occurrences of "../". E.g.

/home/kwan/rpm/RPM/../SPECS/../../../../bin/ls

would first reduce to:

/home/kwan/rpm/SPECS/../../../../bin/ls

Then to:
/bin/ls

You could probably do this with a regex by searching for the first
occurrecnce of "../" then removing the directory immediately preceding.
Loop through the RAWNAME until no more "../" exist. At this point you'd
have the fullname.

-- 
The Digital Hermit      Unix and Linux Solutions
http://www.digitalhermit.com
kwan@digitalhermit.com
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:33:37 EDT