7 April 2008 2 comments Linux
This blog post is 14 years old! Most likely, its content is outdated. Especially if it's technical.
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?
- Previous:
- Lesson learnt with creating DOM element with jQuery 4 April 2008
- Next:
- Mixing in new-style classes in Zope 2.7 9 April 2008
- Related by category:
- Linux tip: du --max-depth=1 27 September 2007 Linux
- How to create-react-app with Docker 17 November 2017 Linux
- Be very careful with your add_header in Nginx! You might make your site insecure 11 February 2018 Linux
- set -ex - The most useful bash trick of the year 31 August 2014 Linux
- Run something forever in bash until you want to stop it 13 February 2018 Linux
- Related by keyword:
- set -ex - The most useful bash trick of the year 31 August 2014
- Run something forever in bash until you want to stop it 13 February 2018
- Read in passwords with bash 25 March 2005
- A neat trick to zip a git repo with a version number 1 September 2017
- Catching a carriage return in bash 23 October 2006
If you are using bash, you can use
echo $PWD/todo.sh
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