I often need to know the path to a file so that I can put that in an email for example. The only way I know is to copy and paste the output of pwd followed by a slash / followed by the name of the file. This is too much work so I wrote a quick bash script to combine this into one. Now I can do this:


$ cd bin
$ pwdf todo.sh 
/home/peterbe/bin/todo.sh

I call it pwdf since it's pwd + file. Here's the code for the curious:


#!/bin/bash
echo -n `pwd`
echo -n '/'
echo $1

Is there no easier way built in into Linux already?

Comments

Pete

If you are using bash, you can use
echo $PWD/todo.sh

Samat Jain

Not sure if it was part of GNU coreutils when you wrote this, but there's readlink[1]. Use:

readlink -f the-file

[1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?readlink

Your email will never ever be published.

Previous:
Lesson learnt with creating DOM element with jQuery April 4, 2008 JavaScript
Next:
Mixing in new-style classes in Zope 2.7 April 9, 2008 Zope
Related by category:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
brotli_static in Nginx November 8, 2024 Linux
Be very careful with your add_header in Nginx! You might make your site insecure February 11, 2018 Linux
Linux tip: du --max-depth=1 September 27, 2007 Linux
Related by keyword:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
How to intercept and react to non-zero exits in bash February 23, 2023 Bash, GitHub
Run something forever in bash until you want to stop it February 13, 2018 Linux
How to count the most common lines in a file October 7, 2022 Linux, Bash, macOS