• Post Reply Bookmark Topic Watch Topic
  • New Topic

Navigating to previous directory  RSS feed

 
Mouly Kumaraswamy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a command to move to the previously visited directory in a session.
For example, if I am in "/tmp" and then I go to "/home/name" then is there a command that will take me to "/tmp". (Discounting of course cd /tmp ).
I'm looking for a command analogous to browser back/forward buttons.

I using Korn shell, but commands from other shells are also welcome.
[ September 22, 2006: Message edited by: Mouly Kumaraswamy ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if your ksh has it, but I make quite a lot of use of "pushd" and "popd" in bash.

If you use "pushd" instead of "cd" to change to a directory, you can return using popd. Especially clever is that way that "pushd" on its own (without the name of a directory to change to) swaps the current and previous directories, and can be done any number of times if you need to hop back and forth between two dirs.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "~-" sequence is the symbol for "last directory".

So

will take you there.

On my Fedora box, this also works:
 
Tim Holloway
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check and see if your shell sets an environment variable named LASTDIR.

As you can see, there's lots of ways. You just have to pick one that matches your shell and your personal preferences.
 
Mouly Kumaraswamy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working in AIX.

cd ~- and cd - worked

This was something I was searching for a long time.

Thank you all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!