Quick note post. I wanted to document this handy little Unix command for spitting out the absolute path of a file:
cd ~/projects/<project>/docs
ls
thing.md
realpath thing.md
/path/to/home/projects/<project>/docs/thing.md
So, if thing.md
lives at ~/projects//docs/thing.md, we'd get something like...
/path/to/home/projects/<project>/docs/thing.md
Especially when dealing with LLMs (needing to reference paths on your machine for the LLM to read), this is a handy one to have floating around your brain.
My only gripe is this has that old school linux command naming style when it should be something like ap
or abspath
. Aliases to the rescue!
alias ap="realpath"
alias abspath="realpath"
alias absolute_path="realpath"
Pop this in your Bash or ZSH config and open a new terminal:
cd ~/projects/<project>/docs
ls
thing.md
ap thing.md
/path/to/home/projects/<project>/docs/thing.md
Enjoy!