Monday, May 11, 2009

How do I know what directory I am in?

If you're like me, you are in and out of so many directories all the time you forget which directory you are in. Fortunately, there is a command that will tell you exactly that. It's called pwd, that's short for print working directory. At the command line just type pwd like this and it will print out where you are:

> pwd
/usr/users/eparker/some/dir/

We can build on what we just learned about shell scripts here. If we wanted to have a script become aware of what directory it's in we would do something like this:

#!/bin/sh

DIR=`pwd`
echo $DIR

Give that a try.

Commands used in this post: pwd


No comments: