8/13 Is there a unix command to print the full filesystem path of
something? e.g.
% pwd
/home/troll
% print-full-path drivel
/home/troll/drivel
\_ function print-full-path { (cd "$1"; pwd); }
Implementation as a csh alias left as an exercise.
\_ that doesn't work... $1 could be a file
\_ You need something like:
FDIR=`dirname "$relpath"`
FBASE=`basename "$relpath"`
FABS="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
\_ christ. ok the answer is "no, you need a script".
\_ which foo
\_ Ok here's my little perl script for this, if anyone cares. -op
\_ locate foo
whereis foo
find `pwd` -name foo -maxdepth 1
echo `pwd`/foo
\_ that last thing would work but I wanted symbolic links
\_ `pwd`/foo would work but I wanted symbolic links
and relative paths converted to absolute paths.
The others don't work in general.
\_ Here's my perl script for this, if anyone cares. -op
#!/usr/bin/perl
chop($cwd = `pwd`);
foreach $arg (@ARGV) {
chdir $cwd;
chop($rel = `dirname $arg`);
chop($base = `basename $arg`);
chdir $rel || die "path not found: $rel\n";
chop($full = `pwd`);
print $full;
print "/" if ($full ne "/");
print $base if ($base ne "/");
print "\n";
}
\_ Look up chomp() as a chop() replacement for removing \n. |