1

Possible Duplicate:
bash/fish command to print absolute path to a file

Say I'm in a directory /usr/temp/foo, which has a file named bar.txt

How do I get the fullpath of bar.txt? (which should be /usr/tem/foo/bar.txt)

4
  • euh, echo /usr/temp/foo/bar.txt...?
    – user529758
    Commented Sep 16, 2012 at 19:42
  • No, but if I have 1000 files, I wouldn't want to do echo pwd ... for all 1000 of those Commented Sep 16, 2012 at 19:46
  • Then save $(pwd) in a variable, and prepend the variable.
    – dstromberg
    Commented Sep 16, 2012 at 19:53
  • bash already has a variable $PWD that stores the current working directory.
    – chepner
    Commented Sep 16, 2012 at 20:40

1 Answer 1

2

Try:

readlink -f bar.txt

Extra text to make SO happy.

3
  • Perhaps, but realpath isn't by default on my mint machine. I figured readlink as part of the GNU tools, would be more common. Commented Sep 16, 2012 at 20:36
  • How about printing fullpaths of all files ending with certain extension? I've tried readline -f *.c (all C-source files), but it didn't seem to work? Commented Sep 17, 2012 at 0:01
  • Combine it with find: find . -name '*.c' -exec readlink -f {} \; Commented Sep 17, 2012 at 0:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.