Command Line Tips – pwd

Using the unix command line, the most commonly used tool is pwd. It prints the working directory, meaning the directory the console is currently targeted at. This is done by simply writing the current value of the global variable $PWD to the screen. You can do this by hand using echo $PWD. If you change the directory with cd, you change the variable $PWD and, therefore, the output of the command pwd. For convinience, the system stores the previous value of $PWD in the variable $OLDPWD. This $OLDPWD variable can be printed to the screen using echo $OLDPWD.

Tip: Using cd –, you can change the working directory to the previous working directory.

Example:

user@host /test $ pwd
/test

user@host /test $ echo $PWD
/test

user@host /test $ cd sub

user@host /test/sub $ pwd
/test/sub

user@host /test/sub $ echo $OLDPWD
/test

user@host /test/sub $ cd -

user@host /test $ cd -

user@host /test/sub $

Note: global variables should be written in capital letters, as shown above. Use lower case letters for your own local variables!

PS: Note the all new, well designed favicon!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s